Commit f6b706a
committed
Fix race condition in concurrent artifact additions
This fixes a race condition where concurrent 'podman artifact add'
commands for different artifacts would result in only one artifact
being created, without any error messages.
The root cause was in the artifact store's Add() method, which
would:
1. Acquire lock
2. Read OCI layout index
3. Create ImageDestination (which snapshots the index)
4. RELEASE lock (optimization for blob copying)
5. Copy blobs (while unlocked)
6. Reacquire lock
7. Commit changes (write new index)
When two concurrent additions happened:
- Process A: Lock → Read index → Create dest A → Unlock → Copy blobs
- Process B: Lock → Read index (no artifact A!) → Create dest B → Unlock
- Process A: Lock → Commit (write index with A)
- Process B: Lock → Commit (write index with B, OVERWRITING A)
The fix keeps the lock held for the entire operation. While this
reduces concurrency for blob copying, it prevents the index file
corruption that caused artifacts to be lost.
Changes:
- Remove lock release/reacquire around blob copying in store.Add()
- Simplify lock management (no more conditional unlock)
Fixes: containers/podman#27569
Generated-with: Cursor AI
Signed-off-by: Daniel J Walsh <[email protected]>1 parent aa970d2 commit f6b706a
1 file changed
+7
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | 228 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 229 | + | |
235 | 230 | | |
236 | 231 | | |
237 | 232 | | |
| |||
304 | 299 | | |
305 | 300 | | |
306 | 301 | | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
311 | 307 | | |
312 | 308 | | |
313 | 309 | | |
| |||
353 | 349 | | |
354 | 350 | | |
355 | 351 | | |
356 | | - | |
357 | | - | |
| 352 | + | |
358 | 353 | | |
359 | 354 | | |
360 | 355 | | |
| |||
0 commit comments