about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/download.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-05T09·54-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-05T18·29+0000
commitf10d60a4543c39cb42f43159a18c9479e07ec56c (patch)
treeab022aeab4c3fd40f0dacf747d63838397dcd267 /third_party/nix/src/libstore/download.cc
parent3f923b2aa0d976fb18e7038d4e2701e878c6784b (diff)
fix(3p/nix/store): fix race condition in downloader r/1598
In certain circumstances, the decompression thread could race ahead of the downloader thread and process the same chunk twice. Clear the data buffer while the lock is held to prevent this kind of incident.

Change-Id: I19a84a0c5768d1228c6c18a7664a7b8893ef96de
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1658
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libstore/download.cc')
-rw-r--r--third_party/nix/src/libstore/download.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc
index e73181e73109..fdc14b376235 100644
--- a/third_party/nix/src/libstore/download.cc
+++ b/third_party/nix/src/libstore/download.cc
@@ -835,7 +835,8 @@ void Downloader::download(DownloadRequest&& request, Sink& sink) {
         state.wait(state->avail);
       }
 
-      chunk = state->data;
+      chunk = std::move(state->data);
+      state->data = std::string();
 
       state->request.notify_one();
     }