Make async lock initialization thread-safe - #2073
Conversation
Eagerly create the process-local lock so concurrent first callers cannot receive different lock objects. Recreate it after fork and add a deterministic concurrent regression test. Fixes fsspec#1783
|
The fix itself is correct, and actually fixes more than the PR description says: eagerly creating I did find a problem with def get_lock():
global _lock
if not _lock:
_lock = threading.Lock()
return _lockand reran the test: it still passed in ~0.09s. The issue is the test calls Might be worth dropping the |
get_lock()lazily initialized the module lock without synchronization, so concurrent first callers could receive different locks and initialize duplicate I/O loops. Initialize the process-local lock eagerly, recreate it after fork, and cover the race with a deterministic two-thread test.Closes #1783
Tests:
pytest -q(1493 passed, 215 skipped, 2 xfailed)