You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
copying from s3 cache buffers entire download in memory, causes segfault #12403
When copying a large path from an s3-based cache, the nix binary appears to buffer the entire download into memory.
When the path is large enough (above approximately 3.5GB) this also reliably causes nix to segfault.
I can only reproduce for an s3-based nix cache. If I use an HTTP cache, memory usage stays low and constant.
Steps To Reproduce
cd$(mktemp -d)
dd if=/dev/urandom of=./random_4g.bin bs=1M count=4096
path=$(nix store add-path . --name large-random)# copy path to s3 store
nix copy --from local --to <the s3 cache>$path# delete it from the local store
nix store delete $path# attempt to copy from s3 store
nix copy --to local --from <the s3 cache>$path# experience segfault# 74861 segmentation fault nix copy --to local /nix/store/rv559vmhs7751xizmfnxk5bwyjhfizpa-large-random
Expected behavior
Nix uses fixed amount of memory and does not segfault.
lib curl has support for AWS Authentication built in these days. We just have to implement the AWS credential chain and we drop the AWS-CPP-SDK dependency and just do S3 upload and download with http-binary-cache-store's libcurl-backed implementation
aws-cpp-sdk has historically not been the most nice of dependencies to manage. I'm not involved in nix day to day development but personally I'd love for the dependency to be softer. Just for the fact that nix then doesn't link against 3 different TLS libraries
I can confirm this behavior.
On machines with little RAM we simply can't download large packages from s3.
Instead we have to disable substituters for local build and this is very inconvenient
Activity
arianvp commentedon Feb 6, 2025
There is a FIXME in the code for this :/
nix/src/libstore/s3-binary-cache-store.cc
Line 427 in fc83c6c
s3.getObjectindeed seems to buffer the entire request into memory:nix/src/libstore/s3-binary-cache-store.cc
Line 159 in fc83c6c
We should instead use the S3 TransferManager for streamed get https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/examples-s3-transfermanager.html
We're already using the TransferManager for uploads; but not for downloads :/
arianvp commentedon Feb 6, 2025
Other option:
lib curl has support for AWS Authentication built in these days. We just have to implement the AWS credential chain and we drop the AWS-CPP-SDK dependency and just do S3 upload and download with http-binary-cache-store's libcurl-backed implementation
arianvp commentedon Feb 6, 2025
Seems for uploading we also only use
TransferManagerwhenmultipart-upload=truewhich is completely undocumented and defaults tofalsenix/src/libstore/s3-binary-cache-store.hh
Line 87 in fc83c6c
andrewhamon commentedon Feb 7, 2025
That is an interesting option. Seems kinda high effort. Is AWS-CPP-SDK something nix is eager to drop?
arianvp commentedon Feb 7, 2025
aws-cpp-sdk has historically not been the most nice of dependencies to manage. I'm not involved in nix day to day development but personally I'd love for the dependency to be softer. Just for the fact that nix then doesn't link against 3 different TLS libraries
guskovd commentedon Mar 13, 2025
I can confirm this behavior.
On machines with little RAM we simply can't download large packages from s3.
Instead we have to disable substituters for local build and this is very inconvenient
arianvp commentedon Mar 13, 2025
There's a PR that seems to address this: #6824
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
31 remaining items
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
refactor(libstore): replace AWS SDK with curl-based S3 implementation
lovesegfault commentedon Oct 16, 2025
This should be fixed now that #13752 has landed, can someone test and confirm?
lovesegfault commentedon Oct 23, 2025
Yup, this is fixed now!