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

Commit

Permalink
Fix socket leak in Java Cloud Debugger (external version only)
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111476982
  • Loading branch information
vladlf authored and Vlad Lifliand committed Jan 7, 2016
1 parent c8bd2c3 commit 057d2f1
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ public ListActiveBreakpointsResult listActiveBreakpoints() throws Exception {
response = gson.fromJson(reader, ListActiveBreakpointsResponse.class);
} catch (IOException e) {
if (connection.get().getResponseCode() == 409) {
// We have to close the error stream. Otherwise the network connection leaks.
connection.get().getErrorStream().close();
return LIST_ACTIVE_BREAKPOINTS_TIMEOUT;
}

Expand Down Expand Up @@ -445,6 +447,8 @@ public void transmitBreakpointUpdate(String format, String breakpointId, byte[]
try {
connection.get().getInputStream().close();
} catch (IOException e) {
// We always call readErrorStream to close the error stream to avoid socket leak.
String errorResponse = readErrorStream(connection.get());
int responseCode = connection.get().getResponseCode();

// We consider all application errors (5xx) and timeout (408) to be transient errors
Expand All @@ -454,7 +458,7 @@ public void transmitBreakpointUpdate(String format, String breakpointId, byte[]
// There is no point in retrying the transmission. It will fail.
warnfmt(e, "Failed to transmit breakpoint update, debuggee: %s, breakpoint ID: %s, "
+ "response: %s\n%s", debuggeeId, breakpointId,
connection.get().getResponseMessage(), readErrorStream(connection.get()));
connection.get().getResponseMessage(), errorResponse);
return;
}

Expand Down

1 comment on commit 057d2f1

@arvindstutzen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for it

Please sign in to comment.