about summary refs log tree commit diff
path: root/tools/nixery/default.nix
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2022-09-19T07·30+0200
committertalyz <kim.lindberger@gmail.com>2022-09-19T11·28+0000
commit28417afbb4d8776501f9ae3ecead5859707488b9 (patch)
treedcb243f44d6c8f428ab8959cf188890e4a37aa4e /tools/nixery/default.nix
parentadf092a26be9da18448e96e1e6198d543d187c63 (diff)
fix(nixery): Avoid race when the same image is fetched in parallel r/4924
Remove a race condition which appears when uploadHashLayer is called
with the same key from multiple threads simultaneously. This can
easily happen when the same image path is requested by multiple
clients at the same time. When it does, a 500 status is returned and
the following error message is logged:

{
  "context": {
    "filePath": "github.com/google/nixery/builder/builder.go",
    "lineNumber": 440,
    "functionName": "github.com/google/nixery/builder.uploadHashLayer"
  },
  "error": "rename /var/lib/nixery/staging/<hash> /var/lib/nixery/layers/<hash>: no such file or directory",
  "eventTime": "...",
  "layer": "<hash>",
  "message": "failed to move layer from staging",
  ...
}

To solve this issue, introduce a mutex keyed on the uploaded hash and
move all layer caching into uploadHashLayer. This could additionally
provide a small performance benefit when an already built image is
requested and NIXERY_PKGS_PATH is set, since symlink layers and config
layers are now also cached.

Change-Id: I50788a7ec7940cb5e5760f244692e361019a9bb7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6695
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tools/nixery/default.nix')
-rw-r--r--tools/nixery/default.nix2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/nixery/default.nix b/tools/nixery/default.nix
index 529794e596..74cb588a39 100644
--- a/tools/nixery/default.nix
+++ b/tools/nixery/default.nix
@@ -69,7 +69,7 @@ depot.nix.readTree.drvTargets rec {
     doCheck = true;
 
     # Needs to be updated after every modification of go.mod/go.sum
-    vendorSha256 = "115dfdhpklgmp6dsy59bp0i9inqim208lf1sqbnl9jy91bnnbl32";
+    vendorSha256 = "sha256-io9NCeZmjCZPLmII3ajXIsBWbT40XiW8ncXOuUDabbo=";
 
     buildFlagsArray = [
       "-ldflags=-s -w -X main.version=${nixery-commit-hash}"