This is an archive of the discontinued LLVM Phabricator instance.

Fixed a race condition in PrecompiledPreamble.
ClosedPublic

Authored by ilya-biryukov on Aug 9 2017, 9:40 AM.

Details

Summary

Two PrecompiledPreambles, used in parallel on separate threads,
could be writing preamble to the same temporary file.

Diff Detail

Repository
rL LLVM

Event Timeline

ilya-biryukov created this revision.Aug 9 2017, 9:40 AM
klimek added inline comments.Aug 10 2017, 3:18 AM
lib/Frontend/PrecompiledPreamble.cpp
470–471 ↗(On Diff #110418)

I don't understand that yet - why does keeping the file open around the EC check change any of the behavior?
Generally, both create the file, right? So only the first one should get no error?

ilya-biryukov added inline comments.Aug 10 2017, 3:39 AM
lib/Frontend/PrecompiledPreamble.cpp
470–471 ↗(On Diff #110418)

createTemporaryFile without fd does not create a file, only checks if the it exists, hence the race condition. Do you think a better solution would be to make it create an empty file and close it right away, similarly to what this function does now?

createTemporaryFile with fd does not have that problem, it actually tries to create a file until it succeeds.

klimek accepted this revision.Aug 10 2017, 4:38 AM

LG, as discussed in person, it's probably a good idea to try to get rid of the non-file-creating version, if possible, or at least fix the comments on the functions to make this behavior clear.

This revision is now accepted and ready to land.Aug 10 2017, 4:38 AM
This revision was automatically updated to reflect the committed changes.