Commit 671f9c5
Fix SnapshotReader temp-file collision when concurrent readers open the same compressed snapshot
Summary:
For compressed `.pytb` inputs, `SnapshotReader::open()` decompresses into a temp file and mmaps it `MAP_SHARED` with `PROT_READ | PROT_WRITE` so the rest of the reader can resolve offsets through `data_`. The temp path was deterministic — `<path>.decompressed.tmp` — which means two `SnapshotReader::open(path)` calls against the same compressed file (commonly a Python process plus a sibling `tintype_debug_launcher` subprocess attached via dapper) collide on that path. The second open is `O_RDWR | O_CREAT | O_TRUNC` followed by `ftruncate(decompressedSize)`, which through the shared inode zero-fills the first reader's mmap. `getManifest()` then returns `decompressedSize` bytes of `\0` until the second `ZSTD_decompress` finishes repopulating the file (~tens of milliseconds). In our case `extract_revision()` saw the null buffer, raised `json.JSONDecodeError: Expecting value: line 1 column 1 (char 0)`, and the deepdump python postmortem bootstrapper aborted before the agent ever ran.
This diff switches the compressed-input path to `mkstemp(<path>.decompressed.XXXXXX)`, mirroring the pattern already used by `SnapshotWriter::open` (`mkstemp("/tmp/snapshot_XXXXXX")`). Each reader gets its own temp file, so concurrent opens cannot race on the same inode. `close()` already unlinks `tempFilePath_`, so cleanup is unchanged. The mode goes from `0644` to `0600` (mkstemp default), which is stricter and consistent with the writer. Adds `<cstdlib>` for `mkstemp` and `<vector>` for the writable template buffer.
Reviewed By: aperez
Differential Revision: D103755545
fbshipit-source-id: 64e44529801ac82d986c764ed119c6f8786b37a11 parent 7e0f7bd commit 671f9c5
1 file changed
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | | - | |
152 | | - | |
153 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
154 | 163 | | |
155 | | - | |
| 164 | + | |
156 | 165 | | |
157 | 166 | | |
158 | 167 | | |
| 168 | + | |
159 | 169 | | |
160 | 170 | | |
161 | 171 | | |
| |||
0 commit comments