NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.12k stars 1.47k forks source link

Fetching from a s3 bucket without credentials is slower than with credentials #4857

Open expipiplus1 opened 3 years ago

expipiplus1 commented 3 years ago

Describe the bug

Looking at the tcpdump trace for my minio bucket, I can see that minio itself responds promptly to the http request, hence it's nix which takes a long time to even query the bucket.

The first thing I thought of was that nix is taking a long time looking for credentials past ~/.aws/credentials in the chain, but nothing there looks too expensive...

strace reports that nix is spending quite some time trying to talk to 169.254.169.254. After a quick google

169.254.169.254 is used in Amazon EC2 and other cloud computing platforms to distribute metadata to cloud instances.

So I suppose this is quite fast on AWS, but elsewhere it's waiting for it to time out.

Expected behavior

Nix is speedy in both authenticated and anonymous cases.

nix-env --version output

nix-env (Nix) 2.3.11

expipiplus1 commented 3 years ago

Perhaps when the s3 url contains a non aws endpoint it shouldn't look for credentials at 169.254.169.254.

edolstra commented 3 years ago

I'm surprised this works at all. Apparently aws-sdk-cpp has some fallback for making unauthenticated S3 requests (which it will only use after trying to get credentials). If you don't have credentials, you probably should use the HTTP binary cache interface (e.g. --store https://nix-cache.s3.us-east-1.amazonaws.com).

Probably we should just make this a fatal error.

expipiplus1 commented 3 years ago

ah! that makes a lot of sense. Thanks for explaining @edolstra!

Or in the case of a minio bucket: https://minio.example.com/nix-cache

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info