Commit beda3c4
committed
Fix race condition during parallel coverage testing using Template compiled_path option/method
This race condition can only happen during parallel testing. Assume
you have 2 processes, both trying to compile the same file at the
same time. When using the compiled_path option/method, this
involves writing a file and loading it. That's done with
File.binwrite. However, the way File.binwrite works is it opens
the file for writing, truncating it if it exists, then writes the
data. So in the following situation, you lose the race, and you get
an exception like `undefined method '__tilt_2720' for module
'Tilt::CompiledTemplates'` when trying to load the template:
1. Process A runs File.binwrite
2. Process A truncates file
3. Process A writes file
4. Process B runs File.binwrite
5. Process B truncates file
6. Process A loads (empty) file
7. Process B writes file
8. Process B loads (nonempty) file
In this situation, process A loaded an empty file. Loading an
empty file isn't an error, so processing continues. You don't have
problems until you try to access the method that should have been
defined and it isn't there.
Fix this by writing to a temporary file name that includes the
pid, and then renaming the file to the expected name after
the file has been written successfully. Writing to separate files
avoids the race condition, and the rename is atomic, so this
should avoid the race condition.1 parent e3fd319 commit beda3c4
2 files changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
477 | 482 | | |
478 | 483 | | |
479 | 484 | | |
| |||
0 commit comments