Bug 28412 - Leak of WebCore::XMLHttpRequest object during layout tests
Summary: Leak of WebCore::XMLHttpRequest object during layout tests
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Aaron Boodman
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2009-08-17 16:26 PDT by Mark Rowe (bdash)
Modified: 2009-08-18 21:35 PDT (History)
3 users (show)

See Also:


Attachments
Make XHR leak more obvious (1.44 KB, patch)
2009-08-17 16:26 PDT, Mark Rowe (bdash)
no flags Details | Formatted Diff | Diff
Unfinished fix (1.90 KB, patch)
2009-08-18 14:03 PDT, Alexey Proskuryakov
no flags Details | Formatted Diff | Diff
Combination of previous two patches, plus ChangeLogs (4.65 KB, patch)
2009-08-18 19:01 PDT, Aaron Boodman
mjs: review+
eric: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Rowe (bdash) 2009-08-17 16:26:26 PDT
Created attachment 35001 [details]
Make XHR leak more obvious

While looking at the output of 'run-webkit-tests --leaks' over the last few days I've occasionally noticed instances of WebCore::XMLHttpRequest being leaked.  I wrote a simple patch that uses RefCountedLeakCounter to make it more obvious when this sort of leak is occurring, and narrowed the leaks down to two tests that are run in sequence.  The following command leaks a single XMLHttpRequest instance every time:

./WebKitTools/Scripts/run-webkit-tests --leaks LayoutTests/http/tests/xmlhttprequest/{xhr-onunload,xml-encoding}.html

With the attached patch applied you'll see:
LEAK: 1 XMLHttpRequest

in the output.
Comment 1 Mark Rowe (bdash) 2009-08-17 16:28:55 PDT
I poked at this briefly and it seemed that the XHR instance gained an extra ref during a call to setPendingActivity which was never balanced out.
Comment 2 Mark Rowe (bdash) 2009-08-17 19:11:34 PDT
<rdar://problem/7149500>
Comment 3 Alexey Proskuryakov 2009-08-18 13:41:57 PDT
This regressed in <http://trac.webkit.org/changeset/47291>, where a call to setPendingActivity() was moved to before ThreadableLoader::create().

Even worse, nonCacheRequestInFlight() call was lost in the refactoring.
Comment 4 Aaron Boodman 2009-08-18 13:49:15 PDT
Whoops, I will this.
Comment 5 Alexey Proskuryakov 2009-08-18 14:03:45 PDT
Created attachment 35073 [details]
Unfinished fix

OK, here's what I already have - unfinished and untested. This also fixed a check before setReportUploadProgress() (which is only used by Chromium afaik).
Comment 6 Aaron Boodman 2009-08-18 19:01:07 PDT
Created attachment 35095 [details]
Combination of previous two patches, plus ChangeLogs

I verified this fixes the leak. Also, reran all LayoutTests, no regressions. And it looks correct, so not sure what else I can add.
Comment 7 Maciej Stachowiak 2009-08-18 19:05:44 PDT
Comment on attachment 35095 [details]
Combination of previous two patches, plus ChangeLogs

r=me
Comment 8 Mark Rowe (bdash) 2009-08-18 20:01:27 PDT
Landed in r47478.
Comment 9 Eric Seidel (no email) 2009-08-18 20:03:59 PDT
Comment on attachment 35095 [details]
Combination of previous two patches, plus ChangeLogs

Rejecting patch 35095 from commit-queue.  This patch will require manual commit.

Patch https://bugs.webkit.org/attachment.cgi?id=35095 from bug 28412 failed to download and apply.
Comment 10 Alexey Proskuryakov 2009-08-18 21:35:32 PDT
+            // For now we should only balance the nonCached request count for main-thread XHRs and not
+            // Worker XHRs, as the Cache is not thread-safe.
+            // This will become irrelevant after https://bugs.webkit.org/show_bug.cgi?id=27165 is resolved.

By the way, it seems that moving this and related code to DocumentThreadableLoader could be a nice improvement while we wait for bug 27165.