[client] get_devices_ts_time_ago: document or serialize the concurrent re-auth race (shared session) #182
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
get_devices_ts_time_ago(_batch.py) fans outget_device_ts_time_agoover aThreadPoolExecutor, sharing the singlerequests.Sessionacross worker threads. The docstring already notes thatrequestsgives "no official guarantee" for thread-safety, but a sharper unstated risk exists:With
auto_reauthenabled, a 401 mid-flight makes every worker hit_request's re-auth branch (_core.py:98-104) and call_reauthenticate()concurrently — a cookie-jar race with N duplicate logins and partially-overwritten session state, right when the session just expired and every request is failing.Options (pick one):
_reauthenticate()with athreading.Lockso one thread re-authenticates while the others wait, then retry — small change, no API impact; or_reauthenticate_if_expired()once before spawning workers, and document the residual race; orDone when: chosen option implemented; a test simulates a 401 on the first worker and asserts a single re-auth call; docstring updated accordingly.