-
Notifications
You must be signed in to change notification settings - Fork 7
Detect stale server connections during client idle in transaction #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vadv
wants to merge
6
commits into
master
Choose a base branch
from
fix/detect-stale-client-in-transaction
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f4158c
Detect stale server connections during client idle in transaction
5cdbaa7
Fix spurious server_readable() triggering after BufStream operations
113af6d
Remove client_idle_in_transaction_timeout to simplify the PR
3868f19
Fix stale comment referencing removed 3-branch select
afec397
Remove idle_in_transaction_session_timeout BDD scenario
5b3d884
Refactor: RAII guard for transaction counter, extract wait_for_next_m…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| @rust @rust-4 @stale-server-detection | ||
| Feature: Detect stale server connections during client idle in transaction | ||
| When a client holds a server connection inside a transaction and the server | ||
| terminates (e.g., idle_in_transaction_session_timeout, pg_terminate_backend), | ||
| pg_doorman should detect this and release the pool slot. | ||
|
|
||
| Background: | ||
| Given PostgreSQL started with pg_hba.conf: | ||
| """ | ||
| local all all trust | ||
| host all all 127.0.0.1/32 trust | ||
| """ | ||
| And fixtures from "tests/fixture.sql" applied | ||
|
|
||
| @stale-server-pg-terminate-backend | ||
| Scenario: Detect server killed by pg_terminate_backend | ||
| # Client holds transaction, then backend is killed via pg_terminate_backend | ||
| # pg_doorman should detect via server_readable() and release the slot | ||
| Given pg_doorman started with config: | ||
| """ | ||
| [general] | ||
| host = "127.0.0.1" | ||
| port = ${DOORMAN_PORT} | ||
| admin_username = "admin" | ||
| admin_password = "admin" | ||
| pg_hba.content = "host all all 127.0.0.1/32 trust" | ||
| server_lifetime = 60000 | ||
| server_idle_check_timeout = 0 | ||
|
|
||
| [pools.example_db] | ||
| server_host = "127.0.0.1" | ||
| server_port = ${PG_PORT} | ||
|
|
||
| [[pools.example_db.users]] | ||
| username = "example_user_1" | ||
| password = "" | ||
| pool_size = 1 | ||
|
|
||
| [[pools.example_db.users]] | ||
| username = "postgres" | ||
| password = "" | ||
| pool_size = 2 | ||
| """ | ||
| # Client opens transaction and gets backend_pid | ||
| When we create session "victim" to pg_doorman as "example_user_1" with password "" and database "example_db" | ||
| When we send SimpleQuery "SELECT pg_backend_pid()" to session "victim" and store backend_pid as "victim_pid" | ||
| When we send SimpleQuery "BEGIN" to session "victim" without waiting | ||
| Then we read SimpleQuery response from session "victim" within 2000ms | ||
| When we send SimpleQuery "SELECT 1" to session "victim" without waiting | ||
| Then we read SimpleQuery response from session "victim" within 2000ms | ||
| # Kill the backend through a separate superuser connection | ||
| When we create session "killer" to pg_doorman as "postgres" with password "" and database "example_db" | ||
| When we terminate backend "victim_pid" from session "victim" via session "killer" | ||
| # Wait for pg_doorman to detect the dead server | ||
| When we sleep for 500 milliseconds | ||
| # Pool slot should be released — new client should succeed | ||
| When we create session "client2" to pg_doorman as "example_user_1" with password "" and database "example_db" | ||
| When we send SimpleQuery "SELECT 2" to session "client2" without waiting | ||
| Then we read SimpleQuery response from session "client2" within 5000ms | ||
| Then session "client2" should receive DataRow with "2" | ||
|
|
Oops, something went wrong.
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.
Check failure
Code scanning / CodeQL
Cleartext logging of sensitive information High
Copilot Autofix
AI 5 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.