Skip to content

Remind periodically while a context lock acquisition is blocked - #2105

Open
fzyzcjy wants to merge 1 commit into
tom/refactor-miles/op13-104from
tom/refactor-miles/op13-105
Open

Remind periodically while a context lock acquisition is blocked#2105
fzyzcjy wants to merge 1 commit into
tom/refactor-miles/op13-104from
tom/refactor-miles/op13-105

Conversation

@fzyzcjy

@fzyzcjy fzyzcjy commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Part of #1837

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from 2143343 to eed5783 Compare August 3, 2026 23:43
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 7a70205 to d2eb99a Compare August 4, 2026 00:38
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch 2 times, most recently from 5fcfecc to e3ed318 Compare August 4, 2026 02:36
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 402aad1 to 37462a1 Compare August 4, 2026 06:53
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from e3ed318 to 7238aa6 Compare August 4, 2026 06:53
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 37462a1 to 546ecc7 Compare August 4, 2026 07:23
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from 7238aa6 to 3020b4c Compare August 4, 2026 07:23
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 546ecc7 to 7ce2b5b Compare August 4, 2026 07:31
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch 2 times, most recently from 3de206d to b0bf4fd Compare August 6, 2026 03:46
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch 2 times, most recently from 60d4450 to febcc22 Compare August 6, 2026 07:04
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from b0bf4fd to 5a6ee2a Compare August 6, 2026 07:04
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from febcc22 to b74a0f6 Compare August 9, 2026 23:31
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch 2 times, most recently from 7674e53 to eb6615e Compare August 10, 2026 00:44
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from b8b0c18 to 625f9aa Compare August 10, 2026 05:59
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch 2 times, most recently from bf5e911 to f48e7de Compare August 10, 2026 16:06
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 625f9aa to ee8fe50 Compare August 10, 2026 16:06
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from f48e7de to 9c02fbc Compare August 10, 2026 16:33
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 4e8269b to eb82f68 Compare August 12, 2026 02:48
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch 2 times, most recently from c0cf3b5 to 7970a67 Compare August 12, 2026 09:32
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 0094c14 to f8d66e9 Compare August 12, 2026 14:31
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from 7970a67 to bda3e1e Compare August 12, 2026 14:31
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from f8d66e9 to e7e2e8e Compare August 12, 2026 14:36
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from bda3e1e to e5dc24d Compare August 12, 2026 14:36
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from e7e2e8e to ccb6823 Compare August 12, 2026 23:56
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from e5dc24d to 2befcbd Compare August 12, 2026 23:56
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from ccb6823 to 0754207 Compare August 13, 2026 01:13
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch 4 times, most recently from cf5cb7e to 8cf2805 Compare August 13, 2026 06:00
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch 2 times, most recently from 8183120 to c02c940 Compare August 13, 2026 06:39
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from 8cf2805 to 4c6b14a Compare August 13, 2026 06:39
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from c02c940 to 752d4fa Compare August 14, 2026 04:46
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from 4c6b14a to 61b94ca Compare August 14, 2026 04:46
async def acquire(self) -> None:
assert _held_lock.get() is None, f"Cannot acquire lock {self._name!r}: a context lock is already held"
await self._lock.acquire()
wait_reminder = asyncio.ensure_future(self._remind_while_waiting())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2][unresolved at safe checkpoint #2176 and checked tip #2649] Please avoid spawning a reminder task on every uncontended acquire. Because asyncio.Lock.acquire() can complete without yielding, a tight acquire/release sequence leaves one cancel-requested task and ready callback per call until the loop runs again; on this head, 100,000 calls retained about 91.8 MB before the next yield. Please preserve an allocation-free uncontended path and reliably drain the contended-path reminder without weakening lock fairness or cancellation safety.


waiter = asyncio.create_task(lock.acquire())
with caplog.at_level(logging.INFO, logger="miles.utils.context_lock"):
await asyncio.sleep(0.08)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2][unresolved at safe checkpoint #2176 and checked tip #2649] Please wait on observed reminder events instead of assuming two 10 ms timers run within this 80 ms window. Under a busy or stalled CI event loop, the test sleep and first reminder can become runnable together, so the waiter is cancelled after only one log and this test flakes despite correct reminder behavior; a deterministic 100 ms event-loop stall reproduces it on this head.

@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-104 branch from 752d4fa to dcc0741 Compare August 29, 2026 12:38
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-105 branch from 61b94ca to d38b682 Compare August 29, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants