Repository navigation
fix: clear query state on disconnect/timeout and guard tx rollback - #451
Merged
Merged
Conversation
Claim the active query promise atomically and mark connections disconnected before completing timed-out query futures so woken callers never observe stale running-query or connected states. Clean up pending PostgreSQL query, close-statement, and handshake futures on disconnect and channelInactive, and guard inTransaction and releaseIfNeeded against rolling back or releasing over timed-out, disconnected, or still-querying connections. Fixes #449 Co-authored-by: TywinLanni <sasha291096@gmail.com>
Contributor
|
I checked the code locally against my case and got the expected behavior |
Keep PostgreSQLConnectionDelegate unchanged by passing an explicit onDisconnect callback to PostgreSQLConnectionHandler, release all DataRowMessage ByteBuf slices when currentQuery is cleared across threads, and unwrap CompletionException before attaching suppressed rollback errors.
Extract rollbackAfterFailure, commitAfterSuccess, and shared CompletionException unwrapping/suppression helpers to flatten ConcreteConnectionBase.inTransaction and SuspendingConnection.
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.
Summary
Fixes stale running-query errors (
ConnectionStillRunningQueryException), async-disconnect race windows, and transaction rollback hangs/error-masking after query timeouts or peer disconnects:TimeoutSchedulerImpl(db-async-common): Support an optionalclaimTimeouthook soPostgreSQLConnectionandMySQLConnectionatomically claimqueryPromiseReference, setisTimeout = true, and mark the connection disconnected before completing the queryCompletableFuturewithTimeoutException. Callers woken byTimeoutExceptionnever observeisQuerying() == true,isTimeout() == false, orisConnected() == true.PostgreSQLConnection/PostgreSQLConnectionHandler/PostgreSQLConnectionDelegate(postgresql-async):disconnectedflag inPostgreSQLConnectionHandlerset immediately ondisconnect()andchannelInactivesoisConnected()becomesfalsesynchronously beforeCloseMessagefinishes flushing, preventing subsequent queries (ROLLBACK) or pool validation from passing on an actively closing socket, and completedisconnectionPromisewhen already inactive.queryPromiseReference,closeStatementReference, and handshakeconnectionFutureondisconnect()andchannelInactive(onDisconnect()), without logging falseERRORmessages on already-completed futures.releasePreparedStatementwhen!isConnected().MySQLConnection(mysql-async): Consult@Volatile channelClosedinisConnected(), completedisconnectionPromisewhen closing an unconnected instance, and claimqueryPromiseReferenceatomically on query timeout.ConcreteConnectionBase&SuspendingConnection(db-async-common):inTransaction, when the transaction body fails: skipROLLBACKif!isConnected() || isTimeout()(server rolls back uncommitted transactions on disconnect), disconnect ifisQuerying()is stilltrue(e.g. caller-sidewithTimeout/orTimeout), and catch synchronous/asynchronous rollback errors as suppressed exceptions so the returned future never hangs and the originalTimeoutExceptionis never masked.releaseIfNeeded, avoid callingreleasePreparedStatementon disconnected, timed-out, or still-querying connections when the prepared statement future failed.Related issue: Fixes #449 (reported in #421; supersedes #450 — thanks to @TywinLanni for reporting and investigating)
Checklist
./gradlew clean buildpasses locally