http-client-impl: use Reference.reachabilityFence to make clear the websokect BuilderImpl must stay strongly referenced until after the WebSocketImpl is created. http-client-branch
authordfuchs
Wed, 08 Nov 2017 17:14:43 +0000
branchhttp-client-branch
changeset 55789 b3562d42f3b1
parent 55788 5a59fa72a72a
child 55790 d73370fdf575
http-client-impl: use Reference.reachabilityFence to make clear the websokect BuilderImpl must stay strongly referenced until after the WebSocketImpl is created.
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/WebSocketImpl.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/WebSocketImpl.java	Wed Nov 08 16:39:47 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/WebSocketImpl.java	Wed Nov 08 17:14:43 2017 +0000
@@ -26,6 +26,7 @@
 package jdk.incubator.http.internal.websocket;
 
 import java.io.IOException;
+import java.lang.ref.Reference;
 import java.net.InetSocketAddress;
 import java.net.ProtocolException;
 import java.net.Proxy;
@@ -206,6 +207,11 @@
             // returned from the buildAsync _after_ onOpen has been signalled.
             // This means if onOpen is lengthy, it might cause some problems.
             ws.signalOpen();
+            // make sure we don't release the builder until this lambda
+            // has been executed. The builder has a strong reference to
+            // the HttpClientFacade, and we want to keep that live until
+            // after the raw channel is created and passed to WebSocketImpl.
+            Reference.reachabilityFence(b);
             return ws;
         };
         OpeningHandshake h;