Commit 1e1e008
fix(pool): claim distinct session slots on Windows
_acquire_session guarded its advisory locking behind `if fcntl is None`
and returned pool[0] on Windows. Every concurrent client there was handed
the same session string, which is precisely the collision the pool exists
to prevent: Telegram sees one auth key on two connections and revokes it
permanently for both clients.
singleton.py already solves this, locking through msvcrt on Windows and
fcntl on POSIX, so expose those primitives as try_lock_exclusive/
release_lock and have the pool use them rather than keeping a second,
POSIX-only copy of the same idea.
Two details the Windows path needs: the lock file is opened "a+" instead
of "w", because the lock covers the first byte and truncating a file
another live client holds is refused; and the pid marker is rewritten in
place rather than appended to on every start.
tests/test_session_pool.py simulated a rival client with a direct fcntl
import, so it could not run on Windows at all. It now uses the same
primitive as the code under test. The case asserting that a missing fcntl
yields pool[0] encoded the bug, so it is replaced by one asserting the
claimed slot is genuinely locked against another client.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent a612943 commit 1e1e008
3 files changed
Lines changed: 32 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | 371 | | |
375 | 372 | | |
376 | 373 | | |
| |||
380 | 377 | | |
381 | 378 | | |
382 | 379 | | |
383 | | - | |
384 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
385 | 383 | | |
| 384 | + | |
| 385 | + | |
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
394 | 396 | | |
395 | 397 | | |
396 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
39 | | - | |
| 37 | + | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
| |||
0 commit comments