Skip to content

Bound large database writes and shutdowns on non-reading peers - #1387

Merged
rmcdaniel merged 1 commit into
mainfrom
general/server-1385-bound-writes
Nov 27, 2026
Merged

rmcdaniel merged 1 commit into
mainfrom
general/server-1385-bound-writes

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

Fixes #1385.

What changes

  • Vendored sqlx-mysql (rust/vendor/sqlx-mysql/src/connection/stream.rs):
    • Add MySqlStream::flush and MySqlStream::shutdown shadowing BufferedSocket::{flush,shutdown}, bounding every socket flush and close by the connection's reply_deadline / reply_timeout (45 s for statements, 5 s for release).
    • Route flush_queued and wait_until_ready through self.flush().await? instead of bypassing to self.socket.flush().
    • On timeout, set reply_failed = true and return Error::Io(ErrorKind::TimedOut) so subsequent reads, flushes, and close_hard() shutdowns fail immediately and discard the connection instead of hanging on unflushed buffer bytes.
  • Vendored sqlx-postgres (rust/vendor/sqlx-postgres/src/connection/stream.rs):
    • Add matching PgStream::flush and PgStream::shutdown with the exact same reply_deadline / reply_timeout bound and reply_failed discard behavior.
  • Deterministic qualifications (test_reply_gate.rs, mysql_stall_tests.rs, postgres.rs):
    • Add ReplyGate::hold_upstream so the proxy stops calling read() on the client socket.
    • Add qualification_a_large_write_to_a_non_reading_peer_fails_within_its_bound for both MySQL/MariaDB and PostgreSQL: sends a 24 MiB parameter after preparing the statement, verifies ErrorKind::TimedOut from the write flush within the shortened bound, verifies return_to_pool() discards the connection in < 1 s, and verifies the next acquire() opens a fresh session.
  • Documentation: Update docs/server-reference.md, rust/vendor/sqlx-mysql/DURABLE-PATCH.md, and rust/vendor/sqlx-postgres/DURABLE-PATCH.md.

Verification

  • Local MySQL 8.4: runtime::mysql::stall_tests::qualification_a_{statement_in_flight_on_a_silent_peer_fails_within_its_reply_bound,release_on_a_silent_peer_ends_within_its_reply_bound,large_write_to_a_non_reading_peer_fails_within_its_bound} — 3 passed, 0 failed (3.06 s).
  • Local PostgreSQL 17: runtime::postgres::tests::qualification_a_{statement_in_flight_on_a_silent_peer_fails_within_its_reply_bound,release_on_a_silent_peer_ends_within_its_reply_bound,large_write_to_a_non_reading_peer_fails_within_its_bound} — 3 passed, 0 failed (3.41 s).
  • CI runs the full MySQL 8.0, MariaDB 10.11, and PostgreSQL matrices.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: PASS at head 1640353

  • Issue Bound large writes to a database peer that has stopped reading #1385 requirements satisfied: MySqlStream::{flush, shutdown} and PgStream::{flush, shutdown} bound socket flushes and shutdowns with reply_deadline / reply_timeout (45 s for statements, 5 s for release), set reply_failed = true on timeout, return Error::Io(ErrorKind::TimedOut) ("the database did not accept a write within the connection's bound"), and fail subsequent reads/flushes/shutdowns immediately so the pool discards the connection. docs/server-reference.md and both vendored DURABLE-PATCH.md files are updated.
  • Call-site & edge-case verification: Inherent flush/shutdown shadow BufferedSocket::{flush, shutdown} with no remaining DerefMut or self.socket.flush() bypasses; PgConnection::close_hard() returns immediately instead of hanging on unflushed bytes; TLS-wrapped and (None, None) unbounded paths preserve expected behavior.
  • Qualifications: ReplyGate::hold_upstream + 24 MiB parameter tests in mysql_stall_tests.rs and postgres.rs deterministically prove write-flush timeout, < 1 s discard on return_to_pool(), replacement backend session/PID, and unconditional cleanup.

@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel
rmcdaniel added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit b53810f Nov 27, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bound large writes to a database peer that has stopped reading

1 participant