Repository navigation
fix: keep and cancel delayed NOTIFY tasks in the asyncpg and psqlpy brokers - #94
Merged
Merged
Conversation
…rokers The tasks were created without a reference, so they could be garbage collected while waiting, and shutdown() did not cancel them. A psqlpy producer that shut down its broker and kept running logged 'Task exception was never retrieved ... Pool has been closed' for every pending delayed message. Both brokers now track these tasks and cancel them on shutdown, like the psycopg and aiopg brokers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The asyncpg and psqlpy brokers started the task that sends a delayed NOTIFY with
asyncio.create_task()and kept no reference to it. That has two effects:poll_interval);shutdown()did not cancel it. When a producer shuts down its broker and keeps running (an app reload, tests, the stress harness's producer restart), the psqlpy task woke up after the delay on the closed pool. It loggedTask exception was never retrieved … BaseConnectionPoolError: Pool has been closed, once per pending delayed message. asyncpg checks the pool after the delay, so it did not log anything.Both brokers now keep these tasks and cancel them on shutdown, like the psycopg and aiopg brokers already do. The message itself is not lost either way: workers poll for delayed messages whose delay has passed.
Test: kick a delayed message, shut the broker down, wait past the delay, and check that no unhandled task error was reported. Runs for all four drivers; it fails for psqlpy without the fix.
Found by the stress harness on
main(producer restart with 20 pending delayed kicks: 21 such errors per run).