Repository navigation
Stop temporary KV watchers on errors and cancellation - #1051
ajaykr0905 wants to merge 4 commits into
Conversation
|
@caspervonb, this PR is mergeable but behind current main. It closes temporary KV watchers on success, failure, and cancellation, with real-server lifecycle coverage across supported Python behavior. Could you review it when you have time? I can update the branch before merge. |
|
PTAL @claude |
|
Claude finished @caspervonb's task in 2m 43s —— View job Review complete
SummaryThis is a well-targeted fix with a clear root-cause chain:
Finding:
|
purge_deletes()left its temporary KV watcher subscribed after reading the initial snapshot. Later writes could fill the unconsumed watcher queue and stall connection drain.keys()also retained its watcher when consumer-info lookup or iteration failed or was cancelled.Stop each temporary watcher in
finally. Forpurge_deletes(), release the watcher before performing stream purges. Key filtering, empty-key errors, tombstone selection, and theolderthanretention behavior stay unchanged.The first CI run exposed an existing callback cancellation race on Python 3.8–3.10. Older
asyncio.wait_for()can consume cancellation when its awaited future has just completed; the callback task then kept waiting even after unsubscribe. Make the callback loop honor closed state and have JetStream push subscriptions share that state with the underlying callback owner. Delegate unsubscribe to the owner; inherited drain also updates the shared state.The new real-JetStream regressions cover repeated housekeeping, subscription and callback/heartbeat task cleanup, consumer-info and iteration failures, deterministic cancellation, purge failures, 300 subsequent writes, and connection drain. Error/cancellation injection happens after a real watcher has been created; those scenarios use events rather than sleeps to control cancellation.
Validation with nats-server 2.15.0:
db5f8da).ty check nats-core nats-serverexits successfully with three existing unused-ignore warnings.The first full-suite run hit the unchanged five-second deadline in
JSMTest.test_jsm_stream_management_with_offsetwhile creating 300 streams. That test passed its isolated rerun without changing any limits, then the full suite passed. An initial parallel modern-suite run hit two unchanged JetStream connection-setup timeouts; both isolated reruns and the complete JetStream repeat passed with existing limits.AI assistance was used to prepare the implementation and tests. All reported checks ran locally against the repository code and a real NATS server.
Fixes #1050.