Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Concurrent requests for an image that has not yet been cached #38
During concurrent requests (even with concurrency as low as 2), if the image has not yet been cached, a FileExistsException gets thrown:
I discovered this race condition issue while benchmarking performance on a VM running locally using ApacheBench v2.3:
Interesting. I guess this is possible given that there is a delay between the image being generated and actually being saved to disk.
We definitely need a second check right before saving a new image to disk. Unfortunately, that doesn't help prevent generating an image twice. Probably the simplest solution would be to simply write a blank file immediately, even before the image has been generated. Then, when the manipulated image has been generated, replace the temporary file with it.
Thanks for bringing this to my attention, I'll have to patch this in an upcoming release.
@reinink You could have the same issue writing a blank file (i.e. multiple requests trying to write the blank file at the same time). Is there any reason the second request wouldn't just do a silent overwrite (or silent fail)?
There would be a very small performance hit because you're generating it twice, but this would be pretty rare.