@@ -515,21 +515,6 @@ public Runnable start(Listener listener) {
515515 serializingExecutor .execute (new Runnable () {
516516 @ Override
517517 public void run () {
518- // This is a hack to make sure the connection preface and initial settings to be sent out
519- // without blocking the start. By doing this essentially prevents potential deadlock when
520- // network is not available during startup while another thread holding lock to send the
521- // initial preface.
522- try {
523- latch .await ();
524- barrier .await (1000 , TimeUnit .MILLISECONDS );
525- } catch (InterruptedException e ) {
526- Thread .currentThread ().interrupt ();
527- } catch (TimeoutException | BrokenBarrierException e ) {
528- startGoAway (0 , ErrorCode .INTERNAL_ERROR , Status .UNAVAILABLE
529- .withDescription ("Timed out waiting for second handshake thread. "
530- + "The transport executor pool may have run out of threads" ));
531- return ;
532- }
533518 // Use closed source on failure so that the reader immediately shuts down.
534519 BufferedSource source = Okio .buffer (new Source () {
535520 @ Override
@@ -549,6 +534,22 @@ public void close() {
549534 Socket sock ;
550535 SSLSession sslSession = null ;
551536 try {
537+ // This is a hack to make sure the connection preface and initial settings to be sent out
538+ // without blocking the start. By doing this essentially prevents potential deadlock when
539+ // network is not available during startup while another thread holding lock to send the
540+ // initial preface.
541+ try {
542+ latch .await ();
543+ barrier .await (1000 , TimeUnit .MILLISECONDS );
544+ } catch (InterruptedException e ) {
545+ Thread .currentThread ().interrupt ();
546+ } catch (TimeoutException | BrokenBarrierException e ) {
547+ startGoAway (0 , ErrorCode .INTERNAL_ERROR , Status .UNAVAILABLE
548+ .withDescription ("Timed out waiting for second handshake thread. "
549+ + "The transport executor pool may have run out of threads" ));
550+ return ;
551+ }
552+
552553 if (proxiedAddr == null ) {
553554 sock = socketFactory .createSocket (address .getAddress (), address .getPort ());
554555 } else {
@@ -1459,4 +1460,4 @@ public void alternateService(int streamId, String origin, ByteString protocol, S
14591460 // TODO(madongfly): Deal with alternateService propagation
14601461 }
14611462 }
1462- }
1463+ }
0 commit comments