@@ -386,6 +386,8 @@ public ListActiveBreakpointsResult listActiveBreakpoints() throws Exception {
386386 response = gson .fromJson (reader , ListActiveBreakpointsResponse .class );
387387 } catch (IOException e ) {
388388 if (connection .get ().getResponseCode () == 409 ) {
389+ // We have to close the error stream. Otherwise the network connection leaks.
390+ connection .get ().getErrorStream ().close ();
389391 return LIST_ACTIVE_BREAKPOINTS_TIMEOUT ;
390392 }
391393
@@ -445,6 +447,8 @@ public void transmitBreakpointUpdate(String format, String breakpointId, byte[]
445447 try {
446448 connection .get ().getInputStream ().close ();
447449 } catch (IOException e ) {
450+ // We always call readErrorStream to close the error stream to avoid socket leak.
451+ String errorResponse = readErrorStream (connection .get ());
448452 int responseCode = connection .get ().getResponseCode ();
449453
450454 // We consider all application errors (5xx) and timeout (408) to be transient errors
@@ -454,7 +458,7 @@ public void transmitBreakpointUpdate(String format, String breakpointId, byte[]
454458 // There is no point in retrying the transmission. It will fail.
455459 warnfmt (e , "Failed to transmit breakpoint update, debuggee: %s, breakpoint ID: %s, "
456460 + "response: %s\n %s" , debuggeeId , breakpointId ,
457- connection .get ().getResponseMessage (), readErrorStream ( connection . get ()) );
461+ connection .get ().getResponseMessage (), errorResponse );
458462 return ;
459463 }
460464
0 commit comments