Skip to content

Protect Transaction#close in Database#runAsync from cancellation - #13754

Open
jkt-signal wants to merge 1 commit into
apple:mainfrom
jkt-signal:protect-transaction-close-future
Open

Protect Transaction#close in Database#runAsync from cancellation#13754
jkt-signal wants to merge 1 commit into
apple:mainfrom
jkt-signal:protect-transaction-close-future

Conversation

@jkt-signal

Copy link
Copy Markdown

FDBDatabase#runAsync returns 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 of CompletableFuture#whenComplete(/* close the open transaction */).

Unfortunately, this means that if the returned future is cancelled, the whenComplete callback is also not called, resulting in the last-opened transaction not being closed, and in turn Transaction not closed warnings appearing on stderr.

This change fixes that problem by swapping the order of two CompletableFuture method calls, moving the whenComplete above a CompletableFuture#thenApply call that fixes up the return value to what runAsync's future is expected to supply. Cancelling that future is not a problem, since the fixed-up return value would be clobbered by the resulting CancellationException anyway, and CompletableFuture cancellation 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 to FDBDatabase and passes with it.

@jkt-signal
jkt-signal force-pushed the protect-transaction-close-future branch from 5644cb3 to 8910301 Compare July 20, 2026 19:16
@jkt-signal
jkt-signal force-pushed the protect-transaction-close-future branch from 8910301 to f163296 Compare July 20, 2026 19:25
@gxglass gxglass closed this Jul 31, 2026
@gxglass gxglass reopened this Jul 31, 2026
@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-ide on Linux RHEL 9

  • Commit ID: f163296
  • Duration 0:25:01
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: f163296
  • Duration 0:43:53
  • Result: ❌ FAILED
  • Error: Error while executing command: ctest -j ${NPROC} --no-compress-output -T test --output-on-failure. Reason: exit status 8
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-arm on Linux RHEL 9

  • Commit ID: f163296
  • Duration 0:46:21
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: f163296
  • Duration 0:59:10
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: f163296
  • Duration 1:26:05
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos-m1 on macOS 14.x

  • Commit ID: f163296
  • Duration 3:46:07
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos on macOS 14.x

  • Commit ID: f163296
  • Duration 4:13:20
  • Result: ❌ FAILED
  • Error: `Error while executing command: # compatible with bash and zsh
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${HOME}/.ssh_key
    -o ServerAliveInterval=9 ec2-user@${MAC_EC2_HOST} "
    set -e -o noclobber
    BUILDNUM=${CODEBUILD_BUILD_NUMBER}
    WAIT_TIME=14400 # 4 hours
    LOCK_STALE=4500 # 75 minutes
    LOCK=/tmp/ci.lock
    "'

macOS stat flags, not linux compatible

lock_mtime() { stat -f %m $LOCK || echo 0 }
I=0
while ! (echo $BUILDNUM >$LOCK) 2>/dev/null ; do
if (( ++I >= WAIT_TIME )); then
echo "timeout waiting for ci.lock after $I seconds"
exit 1
fi
if (( $(date +%s) - $(lock_mtime) >= LOCK_STALE )); then
echo "lock expired after $LOCK_STALE seconds ..."
# racy but sleep so chances are low
sleep $(( 3 + RANDOM % 8 ))
if (( $(date +%s) - $(lock_mtime) >= LOCK_STALE )); then
echo "lock holder is gone"
rm -f $LOCK
else
echo "new lock holder"
fi
fi
sleep 1
done
echo "acquired ci.lock"
'
. Reason: exit status 1`

  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

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.

3 participants