Protect Transaction#close in Database#runAsync from cancellation - #13754
Open
jkt-signal wants to merge 1 commit into
Open
Protect Transaction#close in Database#runAsync from cancellation#13754jkt-signal wants to merge 1 commit into
Transaction#close in Database#runAsync from cancellation#13754jkt-signal wants to merge 1 commit into
Conversation
jkt-signal
force-pushed
the
protect-transaction-close-future
branch
from
July 20, 2026 19:16
5644cb3 to
8910301
Compare
jkt-signal
force-pushed
the
protect-transaction-close-future
branch
from
July 20, 2026 19:25
8910301 to
f163296
Compare
Contributor
Result of foundationdb-pr-clang-ide on Linux RHEL 9
|
gxglass
approved these changes
Jul 31, 2026
Contributor
Result of foundationdb-pr-clang on Linux RHEL 9
|
Contributor
Result of foundationdb-pr-clang-arm on Linux RHEL 9
|
Contributor
Result of foundationdb-pr on Linux RHEL 9
|
Contributor
Result of foundationdb-pr-cluster-tests on Linux RHEL 9
|
Contributor
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Contributor
Result of foundationdb-pr-macos on macOS 14.x
macOS stat flags, not linux compatiblelock_mtime() { stat -f %m $LOCK || echo 0 }
|
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.
FDBDatabase#runAsyncreturns a future on a complicated chain of retry and cleanup logic to create a transaction, run the user-supplied closure, commit the transaction, and close it. The final future actually returned is the result ofCompletableFuture#whenComplete(/* close the open transaction */).Unfortunately, this means that if the returned future is cancelled, the
whenCompletecallback is also not called, resulting in the last-opened transaction not being closed, and in turnTransaction not closedwarnings appearing on stderr.This change fixes that problem by swapping the order of two
CompletableFuturemethod calls, moving thewhenCompleteabove aCompletableFuture#thenApplycall that fixes up the return value to whatrunAsync's future is expected to supply. Cancelling that future is not a problem, since the fixed-up return value would be clobbered by the resultingCancellationExceptionanyway, andCompletableFuturecancellation does not propagate to parent futures' tasks.We also add a unit test verifying the behavior of
db.runAsync(something).cancel(true)with respect to closing opened transactions. This test reliably fails without the change toFDBDatabaseand passes with it.