Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed race condition in _compress_template (django-compressor#1086)
compressor avoids rendering the same node multiple times by checking for a key in offline_manifest: ``` if key in offline_manifest: continue [... render template ...] offline_manifest[key] = result ``` Multiple _compress_template calls can run concurrently, creating a race condition: each checks for a key in offline manifest, then each proceeds to render template. Finally they try to save the same file at the same time, causing django-compressor#1082. My proposed fix is to atomically * check if the manifest key exists * if it doesn't exist, set it to a placeholder value (None) So, in nutshell, the first "if" part becomes: ``` with offline_manifest_lock: if key in offline_manifest: continue offline_manifest[key] = None ``` I'm not sure where to store the lock, I've put it at the module level currently. Perhaps there's a way to avoid the lock entirely.
- Loading branch information