Skip to content

Fix S3 not interruptting - #12227

Closed
RossComputerGuy wants to merge 1 commit into
NixOS:masterfrom
RossComputerGuy:fix/s3-interrupt
Closed

RossComputerGuy wants to merge 1 commit into
NixOS:masterfrom
RossComputerGuy:fix/s3-interrupt

Conversation

@RossComputerGuy

Copy link
Copy Markdown
Member

Motivation

Fixes #11678

Context

This is my attempt to try and get S3 transfers to interrupt properly. The only problem now is retrying doesn't interrupt but it seems the retry strategy doesn't work if you don't already have a connection.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions Bot added the store Issues and pull requests concerning the Nix store label Jan 10, 2025
@NaN-git

NaN-git commented Jan 12, 2025

Copy link
Copy Markdown
Contributor

AFAIK Curl transfers are interruptible already.

checkInterrupt() throws an exception, i.e. it shouldn't be used within a C framework, if there should be a proper shutdown.

IMHO this patch does not make S3 transfers interruptible because it can't interrupt running transfer.

@edolstra

Copy link
Copy Markdown
Member

This PR didn't work for me, at least this command:

nix eval --impure --expr 'builtins.fetchurl "s3://highlighter-public/405b3ba02ccb2f07ec6aba9f233d4194.mp4?region=ap-southeast-2"'

still doesn't respond to Ctrl-C.

Note that src/libstore/filetransfer.cc isn't involved in S3 transfers since aws-sdk-cpp uses libcurl directly. Since S3Helper::getObject() doesn't (AFAIK) have a callback to check for interrupts, the only way I can think of is to pass it a wrapper std::stringstream that calls checkInterrupt(). (That still wouldn't be perfect, since it would only check for interrupts when it receives data, but it's better than nothing.)

@RossComputerGuy

Copy link
Copy Markdown
Member Author

Yeah, I think the best option might actually be to implement an HTTP client using AWS's API for one and then we could throw some checkInterrupts in it. I tried the PR with that example expression but connecting to my S3 server but it timed out. During the timeout, Ctrl-C didn't work and the retry strategy wasn't even called during that.

@NaN-git

NaN-git commented Jan 13, 2025

Copy link
Copy Markdown
Contributor

I have this code, which might fix the issue. But I cannot test it. It's not ready to be merged yet, e.g. aborting multipart uploads might also be possible with transferManager->CancelAll(). Also act.progress() could throw an exception, which is not caught.

@edolstra

Copy link
Copy Markdown
Member

Apparently aws-cpp-sdk has a HttpClientFactory interface that allows overriding the HTTP client (see https://sdk.amazonaws.com/cpp/api/LATEST/aws-cpp-sdk-core/html/class_aws_1_1_http_1_1_http_client_factory.html). Maybe we can use that to make it use libstore's FileTransfer class, which hopefully would make it interruptable automatically.

@RossComputerGuy

Copy link
Copy Markdown
Member Author

I've started overriding the HttpClientFactory, it does seem like the right direction. I just need to know how to push a FileTransfer request.

@RossComputerGuy

Copy link
Copy Markdown
Member Author

I pushed my current progress on it, still figuring out how FileTransfer works.

@RossComputerGuy

Copy link
Copy Markdown
Member Author
$ ./build/src/nix/nix eval --impure --expr 'builtins.fetchurl "s3://highlighter-public/405b3ba02ccb2f07ec6aba9f233d4194.mp4?region=ap-southeast-3"' -vv
evaluating file '<nix/derivation-internal.nix>'
downloading 'http://169.254.169.254/latest/api/token'...
error:
       … while calling the 'fetchurl' builtin
         at «string»:1:1:
            1| builtins.fetchurl "s3://highlighter-public/405b3ba02ccb2f07ec6aba9f233d4194.mp4?region=ap-southeast-3"
             | ^

       error: download of 'http://169.254.169.254/latest/api/token' was interrupted

Looks like this works.

@RossComputerGuy

Copy link
Copy Markdown
Member Author

It seems it gets stuck pulling. I'm not sure if that is intended. Also does this:

warning: error: unable to download 'http://169.254.169.254/latest/api/token': Timeout was reached (28) Failed to connect to 169.254.169.254 port 80 after 137072 ms: Could not connect to server; retrying in 254 ms

@RossComputerGuy

Copy link
Copy Markdown
Member Author

Looks like it should give up and go to using highlighter-public.s3.ap-southeast-3.amazonaws.com.

@Mic92

Mic92 commented May 16, 2025

Copy link
Copy Markdown
Member

Still needed with #12538 @NaN-git ?

@tomberek

Copy link
Copy Markdown
Contributor

stale

@tomberek tomberek closed this May 19, 2026
@RossComputerGuy
RossComputerGuy deleted the fix/s3-interrupt branch May 19, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3 downloads are not interruptable

5 participants