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
[bug] upload-artifact/merge corrupts files when multiple artifacts contain the same path (concurrent write race condition) #809
When merging multiple artifacts that contain a file at the same path, upload-artifact/merge silently produces a corrupted output file — neither a clean overwrite nor a clean skip, but an interleaved mix of bytes from two concurrent write streams.
Steps to reproduce
Create a matrix build with N parallel jobs (N ≥ 2)
Each job produces an artifact containing a file at the same path (e.g. shared/config.yaml)
Use upload-artifact/merge@v7 to combine all artifacts into one (with separate-directories: false, which is the default)
Download and inspect the merged artifact — the shared file will be corrupted
Root cause
In src/merge/merge-artifacts.ts, all artifacts are downloaded to the same tmpDir with up to PARALLEL_DOWNLOADS = 5 running concurrently:
// https://github.com/actions/upload-artifact/blob/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a/src/merge/merge-artifacts.ts#L44-L51constdownloadPromises=artifacts.map(artifact=>artifactClient.downloadArtifact(artifact.id,{path: tmpDir// ALL artifacts extract to the same directory}))constchunkedPromises=chunk(downloadPromises,PARALLEL_DOWNLOADS)for(constchunkofchunkedPromises){awaitPromise.all(chunk)// up to 5 running concurrently}
When two concurrent extractions both reach a file at the same path, they both call fs.createWriteStream(destPath) simultaneously. Both truncate the file to 0 and start streaming bytes. Their async write() calls interleave at the OS level, producing a corrupted file that is neither copy — a mix of bytes from both streams at a non-deterministic offset.
What did you expect to happen?
One of these three predictable behaviors:
Last writer wins — silently overwrite with the later copy
First writer wins — skip the file if it already exists
Fail with an error — surface the duplicate path conflict and let the user decide
Any of these would be acceptable. Silently producing a corrupted file is not.
Additional notes
This affects any workflow where two or more artifacts contain a file at the same path, regardless of whether the file content is identical or different
The corruption is non-deterministic — the byte offset where the interleaving occurs depends on OS I/O scheduling at runtime
separate-directories: true avoids the concurrent write collision but changes the directory structure of the merged artifact, which is not always acceptable
Activity