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 <grfn@gws.fyi>
This commit is contained in:
Kane York 2020-08-05 02:54:12 -07:00 committed by kanepyork
parent 3f923b2aa0
commit f10d60a454

View file

@ -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();
}