Commit f1de798
Fix data race in decompressed-assembly cache writer
The background writer thread read directly from the shared
uncompressed_assemblies_data_buffer, but on a cache miss that same
buffer is handed to the runtime once the decompress lock is released,
and the runtime may write into the assembly image (the reason the
cache-hit path maps the file MAP_PRIVATE / COW). Concurrent writes
could persist a torn or post-mutation image; since the staleness footer
only hashes the *compressed* payload, that corrupt image would then be
reloaded from cache as if pristine on the next launch.
Take a private snapshot of the decompressed bytes in enqueue_write,
while the caller still holds assembly_decompress_mutex and before the
buffer is exposed to the runtime, so the writer only ever touches
immutable memory it owns. On allocation failure we skip caching that
assembly rather than aborting.
Trade-off: this adds one memcpy per newly-cached assembly on the
first-launch (cache-miss) path and holds the queued snapshots (up to
the touched working set) transiently until the writer drains them.
Subsequent launches hit the mmap path and never enqueue.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 9ba5340 commit f1de798
1 file changed
Lines changed: 27 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
55 | 62 | | |
56 | 63 | | |
57 | 64 | | |
| |||
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
93 | | - | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| |||
212 | 219 | | |
213 | 220 | | |
214 | 221 | | |
215 | | - | |
216 | | - | |
217 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
218 | 228 | | |
219 | 229 | | |
220 | 230 | | |
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
224 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
225 | 243 | | |
226 | 244 | | |
227 | | - | |
| 245 | + | |
228 | 246 | | |
229 | 247 | | |
230 | 248 | | |
| |||
0 commit comments