fix: minor improvements (xact callback leak, pg_net.ttl validation) - #278
Open
utkarash2991 wants to merge 3 commits into
Open
fix: minor improvements (xact callback leak, pg_net.ttl validation)#278utkarash2991 wants to merge 3 commits into
pg_net.ttl validation)#278utkarash2991 wants to merge 3 commits into
Conversation
`net.wake()` called `RegisterXactCallback(wake_at_commit)` in every transaction where `wake_commit_cb_active` was false, i.e. once per transaction that uses pg_net. `RegisterXactCallback` appends a new entry to a backend-wide list in TopMemoryContext on every call and never deduplicates, and nothing ever unregistered it. On a long-lived backend (e.g. behind a connection pooler) that fires webhooks continuously this leaks ~40 bytes per transaction and makes `CallXactCallbacks` walk an ever-growing list on every transaction event, for every transaction on that backend. Register the callback once per backend and keep `wake_commit_cb_active` as the per-transaction gate. The new test measures TopMemoryContext of a backend across 5000 single-statement transactions calling `net.wake()`. Measured on PG 17: 200,120 bytes of growth before this fix, 0 bytes after. Skipped on PG < 14 where `pg_backend_memory_contexts` doesn't exist.
Add a GUC check hook for `pg_net.ttl` that parses the value with `interval_in` and rejects invalid and negative intervals at SET/ALTER SYSTEM/config-reload time, with the interval parser's own message as the error detail. Previously an invalid value was accepted and only failed later inside the worker's expired-response delete. Closes #268.
imor
approved these changes
Sep 8, 2026
imor
left a comment
Contributor
There was a problem hiding this comment.
Test asserts can be improved a bit, otherwise looks good.
| autocommit_sess.execute(text(f"alter system set pg_net.ttl to '{bad}'")) | ||
| msg = str(excinfo.value) | ||
| assert 'invalid value for parameter "pg_net.ttl"' in msg | ||
| assert "invalid input syntax for type interval" in msg |
Contributor
There was a problem hiding this comment.
Can we assert the value of the full error message, that will make it easy to see the complete error we expect users to see as well.
Check the exact primary message and DETAIL line via the driver's diagnostics instead of two substrings, so the test documents the complete error a user sees on ALTER SYSTEM.
utkarash2991
force-pushed
the
fix/ttl-validation-and-xact-callback
branch
from
September 8, 2026 08:45
7da0030 to
40d93d0
Compare
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.
Minor improvements in pg_net:
wake_at_committransaction callback once per backend instead of once per transaction. Fixes a per-backend leak inTopMemoryContextand ever-slowerCallXactCallbackson long-lived connections. Measured 200,120 bytes of growth over 5000 transactions before, 0 after.pg_net.ttlwhen it is set: invalid and negative intervals are rejected atALTER SYSTEMtime with the interval parser's message, instead of being accepted and failing inside the worker. Closes Validatettlconfig #268.Tested on PG 13, 17 (full suite) and 19.
Tracking: PSQL-1652