From f10d60a4543c39cb42f43159a18c9479e07ec56c Mon Sep 17 00:00:00 2001 From: Kane York Date: Wed, 5 Aug 2020 02:54:12 -0700 Subject: fix(3p/nix/store): fix race condition in downloader 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 --- third_party/nix/src/libstore/download.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'third_party/nix/src/libstore') 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(); } -- cgit 1.4.1