Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java

Issue 2903193002: [Cronet] Fix two races/leaks in JavaUrlRequest (Closed)
Patch Set: whoops, put back JavaUrlRequest.java Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
index dd2230df5a96d878bd20fe6dacc3dfb78e417b15..4c973eadba1aa5bad01df3ec7d87158da46c132a 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
@@ -2118,4 +2118,39 @@ public class CronetUrlRequestTest extends CronetTestBase {
((NetworkException) callback.mError).getCronetInternalErrorCode());
}
}
+
+ @SmallTest
+ @Feature({"Cronet"})
+ /**
+ * Open many connections and cancel them right away. This test verifies all internal
+ * sockets and other Closeables are properly closed. See crbug.com/726193.
+ */
+ public void testGzipCancel() throws Exception {
+ String url = NativeTestServer.getFileURL("/gzipped.html");
+ for (int i = 0; i < 100; i++) {
+ TestUrlRequestCallback callback = new TestUrlRequestCallback();
+ callback.setAutoAdvance(false);
+ UrlRequest urlRequest =
+ mTestFramework.mCronetEngine
+ .newUrlRequestBuilder(url, callback, callback.getExecutor())
+ .build();
+ urlRequest.start();
+ urlRequest.cancel();
+ // If the test blocks until each UrlRequest finishes before starting the next UrlRequest
+ // then it never catches the leak. If it starts all UrlRequests and then blocks until
+ // all UrlRequests finish, it only catches the leak ~10% of the time. In its current
+ // form it appears to catch the leak ~70% of the time.
+ // Catching the leak may require a lot of busy threads so that the cancel() happens
+ // before the UrlRequest has made much progress (and set mCurrentUrlConnection and
+ // mResponseChannel). This may be why blocking until each UrlRequest finishes doesn't
+ // catch the leak.
+ // The other quirk of this is that from teardown(), JavaCronetEngine.shutdown() is
+ // called which calls ExecutorService.shutdown() which doesn't wait for the thread to
+ // finish running tasks, and then teardown() calls GC looking for leaks. One possible
+ // modification would be to expose the ExecutorService and then have tests call
+ // awaitTermination() but this would complicate things, and adding a 1s sleep() to
+ // allow the ExecutorService to terminate did not increase the chances of catching the
+ // leak.
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698