Skip to content
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

File Cache Corruption and Exclusive Lock #204

Closed
acinader opened this issue Jan 16, 2020 · 0 comments · Fixed by #200
Closed

File Cache Corruption and Exclusive Lock #204

acinader opened this issue Jan 16, 2020 · 0 comments · Fixed by #200

Comments

@acinader
Copy link

Occasionally when we deploy new code, the routes will be messed up (i.e. the wrong route handler gets called). If I erase the cache file so it gets regenerated, the problem goes away.

My guess at what is happening: when the new code is mv'd into place, which is atomic, two requests come in close together enough that the route cache has started generating, but hasn't finished, so a second route-cache build is initiated and the two builds do interleaving writes which causes a corrupt cache.

I did capture a good chunk of the bad cache file and the corresponding good cache file. What I notice is that in the bad cache file, there are missing entries, i.e. it goes from 5 to 7 skipping 6.

I can post here if it would be useful (I'll need some time to scrub it for any sensitive info if any).

If my hypothesis is correct, I think the simple fix is to add the LOCK_EX flag to this file_put_contents.

On the other hand, if my hypothesis is correct, I'm pretty amazed that there isn't an issue already for others...

acinader added a commit to acinader/FastRoute that referenced this issue Jan 16, 2020
@lcobucci lcobucci linked a pull request Jun 14, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant