You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Local storage does not serialize concurrent uploads from separate threads #2250
Two uploads to the same local object can enter their critical sections together when they run in different threads. upload_object and upload_object_via_stream create separate LockLocalStorage instances, each with its own threading.Lock. On POSIX, the file lock does not exclude another thread in the same process.
Reproduced on current trunk (b2e794d), Python 3.12, macOS:
importtempfileimportthreadingfromlibcloud.storage.drivers.localimportLockLocalStoragewithtempfile.TemporaryDirectory() asdirectory:
first=LockLocalStorage(directory+"/object")
second=LockLocalStorage(directory+"/object", timeout=0.1)
entered=threading.Event()
defwriter():
withsecond:
entered.set()
withfirst:
thread=threading.Thread(target=writer)
thread.start()
thread.join(2)
print(entered.is_set()) # True: both writers hold the lockthread.join()
The second writer should wait or time out until the first releases the lock. Concurrent stream uploads can otherwise overwrite each other's bytes.
A related ordering problem is that __exit__ releases the thread lock before the file lock. Both locks need to cover the same critical section.
AI disclosure: Codex reproduced this bug and prepared the regression tests and proposed fix.
Activity