Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 057d2f1

Browse files
vladlfVlad Lifliand
authored andcommitted
Fix socket leak in Java Cloud Debugger (external version only)
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=111476982
1 parent c8bd2c3 commit 057d2f1

File tree

1 file changed

+5
-1
lines changed
  • src/agent/internals/src/main/java/com/google/devtools/cdbg/debuglets/java

1 file changed

+5
-1
lines changed

src/agent/internals/src/main/java/com/google/devtools/cdbg/debuglets/java/GcpHubClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)