Skip to content

Release encoded bind values when a statement is cancelled while encoding them - #755

Open
zenios wants to merge 1 commit into
pgjdbc:mainfrom
zenios:release-cancelled-bind-values
Open

zenios wants to merge 1 commit into
pgjdbc:mainfrom
zenios:release-cancelled-bind-values

Conversation

@zenios

@zenios zenios commented Oct 2, 2026

Copy link
Copy Markdown
  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Issue description

Fixes #754.

A cancellation that arrives after a statement's bind values are encoded, but before the extended query takes them over, makes collectBindingParameters(…) discard them without releasing them, leaking a pooled buffer per bind value. This releases the discarded values with doOnDiscard(ReferenceCounted.class, ReferenceCountUtil::release), as PostgresqlStatement and ExtendedFlowDelegate already do for discarded frames.

PostgresqlStatementUnitTests.executeCancelledWhileEncodingReleasesEncodedValues cancels the result subscription while the second bind value is being encoded and checks that both encoded buffers are released. It fails without the change.

New Public APIs

None.

Additional context

With Netty's allocator caches disabled, 10,000 statements cancelled from another thread while being subscribed left 379 buffers unreleased with one bind value each, and 4,679 with twenty, before the change; none after it. mvn verify -DskipITs passes on Java 25. The change follows the formatting of the surrounding code.

…ing them.

`PostgresqlStatement` collects the encoded bind values before the extended query takes them over and releases them. A cancellation in between, typically from another thread while the result is being subscribed, dropped the collected values without releasing them, leaking a pooled buffer per bind value. Release the values the collection discards, as the query's message flow already does.

[resolves pgjdbc#754]
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.

Encoded bind values leak when a statement is cancelled while they are encoded

1 participant