-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use an exclusive lock when writing the cache file #205
Use an exclusive lock when writing the cache file #205
Conversation
I suspect that there's a dogpile issue here where, when using the lock, several other requests could queue up to write the cache, so the file could get written multiple times. Accounting for that would require a different strategy to lock both read and write through the whole critical section. Having said that, I'd prefer a dog pile on the file to a corrupt file that makes the site unusable. |
This looks reasonable to me. We should probably also apply that to the 1.x branch. |
There is still a bug here, in that it is possible to require a partially written file. The file should maybe instead be written to disk under a different name, and then renamed to the the real file. |
Yeah, that's a good point. I believes file renames on Linux at least are atomic. |
Yeh, I think so too. |
Shouldnt it go a bit more in this direction https://github.com/webimpress/safe-writer/blob/master/src/FileWriter.php |
Using |
The reading of a partially written cache file explains errors I saw in our logs. Good callout @GrahamCampbell. I don't think that atomic rename is a good full solution. It does not address the cold cache, dogpile problem where more than one request is building the cache file simultaneously. I think that php's flock can do what we really want which is block reads while the cache file is being calculated once. I can take stab at it if that sounds reasonable? FYI: I'm using Slim 3 which depends on FastRoute. |
fyi, i am still getting corrupted cache files. i'll try and capture a corrupt one and post details to the issue |
Closing this in favour #200 (will be backported to v1) |
fixes: #204