Skip to content

AWS: handle premature connection close#15792

Open
kinolaev wants to merge 1 commit intoapache:mainfrom
kinolaev:aws-handle-premature-connection-close
Open

AWS: handle premature connection close#15792
kinolaev wants to merge 1 commit intoapache:mainfrom
kinolaev:aws-handle-premature-connection-close

Conversation

@kinolaev
Copy link
Copy Markdown

During vectorized Parquet reads, S3InputStream opens an unbounded HTTP range request (bytes=pos-) and reads one row group eagerly into memory. While Spark processes that in-memory row group (which can take several minutes for large batches), the client stops reading from S3. The TCP receive buffer fills up, and S3 eventually tears down the stalled connection.

When the next row group read begins, the connection is already dead and Apache HTTP client throws ConnectionClosedException: Premature end of Content-Length delimited message body (expected: x; received: y) (when using apache http client). This only affects files with multiple row groups (typically >128 MB).

The existing retry policy handles SSLException, SocketTimeoutException, and SocketException, but not this case. This PR extends the retry predicate to reopen the stream at the saved position when this specific exception is encountered, while leaving all other ConnectionClosedException variants (e.g. from abort()) unaffected.

Fixes #9674 and #9679.

@github-actions github-actions bot added the AWS label Mar 27, 2026
@kinolaev kinolaev force-pushed the aws-handle-premature-connection-close branch from 5620bbc to 6b8c61c Compare March 27, 2026 18:29
Signed-off-by: Sergei Nikolaev <kinolaev@gmail.com>
@kinolaev kinolaev force-pushed the aws-handle-premature-connection-close branch from 6b8c61c to e4d88c9 Compare March 27, 2026 18:30
Copy link
Copy Markdown
Contributor

@singhpk234 singhpk234 left a comment

Choose a reason for hiding this comment

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

Thanks for reporting this @kinolaev !
I think this stems from the fact that row groups are read sequentially, i had a pr a while back to prefetch the row groups and this would have potentially saved us in this scenario.
PR : https://github.com/apache/iceberg/pull/7279/changes

resuming the connection from last its closed, seems like a way continue the processing,

do you know the case like your, reads ever success ? because if a fresh connection is established and we reprocess this task again from the begining we will still get into same situation ?

Comment on lines +59 to +61
return ex.getClass().getSimpleName().equals("ConnectionClosedException")
&& ex.getMessage() != null
&& ex.getMessage().startsWith("Premature end of Content-Length delimited message body");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a better way to identify this rather than inspecting on exception message (it looks to fragile to me)

@singhpk234 singhpk234 requested a review from danielcweeks March 29, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg Rewrite DataFiles unmanageable behavior

2 participants