Skip to content

Fix memory accounting when message reads are cancelled - #280

Open
ekhodzitsky wants to merge 2 commits into
ozontech:masterfrom
ekhodzitsky:fix/cancelled-read-memory
Open

ekhodzitsky wants to merge 2 commits into
ozontech:masterfrom
ekhodzitsky:fix/cancelled-read-memory

Conversation

@ekhodzitsky

Copy link
Copy Markdown

When a backend exits while a client message is only partially received, wait_for_next_message drops the pending read. Its reservation remains in CURRENT_MEMORY, so later clients can receive SQLSTATE 53200 even after the original client disconnects.

Use a scope guard in both message readers to release the reservation on completion, error, or cancellation. Tests cover partial headers and bodies, overlapping reservations, task cancellation, EOF, and memory-limit rejection. The BDD regression confirms that a reservation is active, terminates the backend, and checks that the next client can query within the configured limit.

Validation:

  • cargo test --workspace --lib --bins --test message_memory: 1254 passed, 1 ignored.
  • BDD @stale-server-detection on PostgreSQL 18.6: 6 scenarios, 130 steps passed.
  • Cancellation regressions fail on the original implementation and pass with the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant