Repository navigation
fix(jdbc): serialize statement close and execute - #89
Merged
Merged
Conversation
magnusp
force-pushed
the
fix/49-concurrent-close-execute
branch
from
October 21, 2026 23:53
3bf7247 to
42f0f66
Compare
This was referenced Oct 22, 2026
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.
Closes #49. Part of #54.
What changed
LibsqlStatementstate transitions (execute,executeQuery,close, result-set installation and removal, generated keys,getResultSet,isClosed,closeOnCompletion) now share one private lock.execute/executeQueryperform the network call outside the lock, re-checkclosedunder the lock, and only attach the result set if close has not won. If close won, the produced result set is closed and not attached.close()closes the current result set and generated keys while holding the lock, then marks the statement closed.LibsqlPreparedStatementreuses the sameassignResultSet/executeResultpaths, so prepared statements get the same guarantee.LibsqlStatementConcurrencyTestwith a deterministic latch seam (beforeResultSetAssignment) between the closed check and result-set installation. The test starts close while execute is paused in the seam, so the race does not depend on timing luck.Contract decision
This is a correctness fix, not an xerial parity change. #47 deliberately keeps execute-after-close working; that remains true: the call still executes and does not throw. The one observable tightening is that a result set produced after the statement is already closed is returned closed instead of open. This is required by #49's acceptance criterion that a closed statement never holds an open result set after execute returns, and it also covers the reproduction where close completes before the next execute starts.
Evidence
Failing before the fix (seam and tests present, locking absent):
Passing after the fix:
The concurrency test was also run five times in a row, all green.
./mvnw spotless:applyand./mvnw spotless:checkpass.Deviations
None for the Hrana transport or sqld. The only intentional behavior change beyond the race is closing a result set produced by an execute on an already-closed statement, described under Contract decision.