Skip to content

fix(libstore/filetransfer): re-enable TCP keep-alive and handle S3's XML errors - #15855

Merged
tomberek merged 4 commits into
NixOS:masterfrom
tomberek:tomberek/dead_socket
May 18, 2026
Merged

fix(libstore/filetransfer): re-enable TCP keep-alive and handle S3's XML errors#15855
tomberek merged 4 commits into
NixOS:masterfrom
tomberek:tomberek/dead_socket

Conversation

@tomberek

@tomberek tomberek commented May 14, 2026

Copy link
Copy Markdown
Contributor

This allows curl to detect drops from both a server (eg: S3) as well as intermediate networking. 30s is to be shorter than commonly used 60s limits on the server side. The theory is that 60s timeout on both server and client led to races that were sometimes lost.

un-reverts: #15522

Motivation

Had connections that died and without keepalive they are not detected for a long time.

@tomberek
tomberek requested a review from Ericson2314 as a code owner May 14, 2026 05:08
@tomberek
tomberek requested review from Mic92 and lovesegfault May 14, 2026 06:54
@xokdvium

Copy link
Copy Markdown
Contributor

We should first implement retries for the S3 400 socket closed errors though.

@Mic92

Mic92 commented May 14, 2026

Copy link
Copy Markdown
Member

Yes, there are errors embedded in xml that we need to handle, otherwise this change will break hydra again...

@tomberek

Copy link
Copy Markdown
Contributor Author

I can start working on the xml error handling, but the idea was that the 60 -> 30s change fixes what was encountered in Hydra.

This allows curl to detect drops from both a server (eg: S3) as well
as intermediate networking. 30s is to be shorter than commonly used 60s
limits on the server side.
@tomberek
tomberek force-pushed the tomberek/dead_socket branch from 51644aa to fcf04ab Compare May 15, 2026 02:35
@tomberek

Copy link
Copy Markdown
Contributor Author

Updated and rebased with S3 error handling (so far just regex like is done in s3-binary-cache-store.cc, not with full XML parsing).

Error codes from https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html#ErrorCodeList

S3 returns transient errors as HTTP 400/503 inside XML. Without parsing these errors are treated as non-retryable.
@tomberek
tomberek force-pushed the tomberek/dead_socket branch from fcf04ab to 631c492 Compare May 15, 2026 02:38
@tomberek tomberek changed the title fix(libstore/filetransfer): re-enable TCP keep-alive fix(libstore/filetransfer): re-enable TCP keep-alive and handle S3's XML errors May 15, 2026
// S3 returns certain retryable errors as HTTP 400/500/503 with XML error codes.
// These take precedence over the generic HTTP status handling below.
// Only parse the response body on status codes where S3 XML errors can appear.
static constexpr std::array<std::string_view, 12> s3RetryableErrors{{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tomberek don't know how much of a difference it makes, but saves some heap allocation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also just de-compiled because I was interested, and it seems that it also generates less code for my variant.

Comment thread src/libstore/filetransfer.cc Outdated
"SlowDown", // HTTP 503 - throttling
"ServiceUnavailable", // HTTP 503 - temporary unavailability
"Throttling", // HTTP 400 - throttling variant
"ThrottledException", // HTTP 400 - throttling variant

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I found a few more errors in the aws-cpp sdk (see commit for link) that are generally re-tried.

The original set only covered 5 error codes. The AWS C++ SDK treats
additional error codes as retryable, including throttling variants
(Throttling, ThrottledException, RequestThrottled), internal error
aliases (InternalFailure, InternalServerError), and clock-related
errors (RequestExpired, RequestTimeTooSkewed).

Also use constexpr std::array<std::string_view> instead of
std::set<std::string> to avoid heap allocation.

Reference: https://github.com/aws/aws-sdk-cpp/blob/3d8614fbd6d2/src/aws-cpp-sdk-core/source/client/CoreErrors.cpp#L27-L55
@Mic92
Mic92 force-pushed the tomberek/dead_socket branch from 919d49f to e3f58bc Compare May 17, 2026 09:48
@tomberek
tomberek added this pull request to the merge queue May 18, 2026
Merged via the queue into NixOS:master with commit 0d9e73a May 18, 2026
16 checks passed
@tomberek
tomberek deleted the tomberek/dead_socket branch May 18, 2026 16:40
@tomberek tomberek added the backport 2.34-maintenance Automatically creates a PR against the branch label Jun 1, 2026
@internal-nix-ci

Copy link
Copy Markdown

Backport failed for 2.34-maintenance, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.34-maintenance
git worktree add -d .worktree/backport-15855-to-2.34-maintenance origin/2.34-maintenance
cd .worktree/backport-15855-to-2.34-maintenance
git switch --create backport-15855-to-2.34-maintenance
git cherry-pick -x 534d3760833283d249f220ac86d5ea8f7f13be8e 631c492f10680808573fe13ba57e937af509edb9 e3f58bc32f5ba830c3ac5ed123fc8dd695fcc204 378753a040c9582f9e2b1c39569f094c1c44f0bf

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

Labels

backport 2.34-maintenance Automatically creates a PR against the branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants