@@ -1039,7 +1039,7 @@ private void innerRun(IOHub hub, SSLContext context, ExecutorService service) {
10391039 agentTrustManager .setDelegate (delegate );
10401040
10411041 events .status ("Handshaking" );
1042- Socket jnlpSocket = connectTcp ( endpoint ) ;
1042+ Socket jnlpSocket = null ;
10431043 Channel channel = null ;
10441044
10451045 try {
@@ -1050,16 +1050,14 @@ private void innerRun(IOHub hub, SSLContext context, ExecutorService service) {
10501050 events .status ("Protocol " + protocol .getName () + " is not enabled, skipping" );
10511051 continue ;
10521052 }
1053- if (jnlpSocket == null ) {
1054- jnlpSocket = connectTcp (endpoint );
1055- }
10561053 if (!endpoint .isProtocolSupported (protocol .getName ())) {
10571054 events .status ("Server reports protocol " + protocol .getName () + " not supported, skipping" );
10581055 continue ;
10591056 }
10601057 triedAtLeastOneProtocol = true ;
10611058 events .status ("Trying protocol: " + protocol .getName ());
10621059 try {
1060+ jnlpSocket = connectTcp (endpoint );
10631061 channel = protocol .connect (
10641062 jnlpSocket ,
10651063 headers ,
@@ -1083,8 +1081,14 @@ private void innerRun(IOHub hub, SSLContext context, ExecutorService service) {
10831081 }
10841082
10851083 // On failure form a new connection.
1086- jnlpSocket .close ();
1087- jnlpSocket = null ;
1084+ if (jnlpSocket != null ) {
1085+ try {
1086+ jnlpSocket .close ();
1087+ } catch (IOException e ) {
1088+ events .status ("Failed to close socket" , e );
1089+ }
1090+ jnlpSocket = null ;
1091+ }
10881092 }
10891093
10901094 // If no protocol worked.
0 commit comments