Skip to content

Fix: abort connection before draining in HttpResponse.disconnect()#2163

Open
Animeshz wants to merge 1 commit into
googleapis:mainfrom
Animeshz:animeshz/fix-disconnect-drain-before-abort
Open

Fix: abort connection before draining in HttpResponse.disconnect()#2163
Animeshz wants to merge 1 commit into
googleapis:mainfrom
Animeshz:animeshz/fix-disconnect-drain-before-abort

Conversation

@Animeshz

Copy link
Copy Markdown

Fixes #1303

After the revert #1427 was merged, this issue was never looked upon. This issue is causing fadvice: SEQUENTIAL (default) file reads in GoogleCloudDataproc/hadoop-connectors#1729 to read the file full from the point it was seeked to. Hence for reading 2gb out of 40gb file, after reading the file for 2gb and calling disconnect()/close() we're still draining the rest of 38gb stream due to this.

HttpResponse.disconnect() calls ignore() (which drains the remaining response body via ContentLengthInputStream.close()) before calling LowLevelHttpResponse.disconnect() (which aborts the socket). This caused callers that close a stream after reading only a prefix of a large response to block for minutes draining bytes they do not need.


Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

HttpResponse.disconnect() previously called ignore() (which drains the
remaining response body via ContentLengthInputStream.close()) before
calling LowLevelHttpResponse.disconnect() (which aborts the socket).
This caused callers that close a stream after reading only a prefix of a
large response to block for minutes draining bytes they do not need.

Fix: call response.disconnect() first to abort the socket, then call
ignore() for cleanup. Any IOException from ignore() on an already-dead
socket is expected and swallowed.

This is the corrected version of googleapis#1315 (reverted in googleapis#1427 because the
original lacked the try-catch around ignore(), causing
TruncatedChunkException to propagate from disconnect()).

Fixes googleapis#1303
@Animeshz Animeshz requested a review from a team as a code owner June 18, 2026 10:08
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Jun 18, 2026
@google-cla

google-cla Bot commented Jun 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpResponse.disconnect() broken for ApacheHttpTransport

1 participant