Skip to content

Fix connection race in concurrent GetLastTimeStamp#387

Merged
SimonCropp merged 2 commits intomainfrom
Fix-connection-race-in-concurrent-GetLastTimeStamp
Apr 21, 2026
Merged

Fix connection race in concurrent GetLastTimeStamp#387
SimonCropp merged 2 commits intomainfrom
Fix-connection-race-in-concurrent-GetLastTimeStamp

Conversation

@SimonCropp
Copy link
Copy Markdown
Owner

Commit d9016cc cached ResolveQuery's Task via Interlocked.CompareExchange
so concurrent callers would share a single query. But each caller that
lost the CompareExchange race still had its own ResolveQuery task running
in the background, executing Open/HasViewServerState/Close against the
caller's own connection. Meanwhile the caller proceeded to Execute against
that same connection, producing "The connection is closed" (production)
or "does not support MultipleActiveResultSets" (local) errors.

Serialize ResolveQuery with a SemaphoreSlim so at most one caller ever
runs it. Strengthen ConcurrencyTests to use closed connections, a
synchronous barrier on dedicated threads, and 20 iterations — reliably
reproduces the race on the old code.

  Commit d9016cc cached ResolveQuery's Task via Interlocked.CompareExchange
  so concurrent callers would share a single query. But each caller that
  lost the CompareExchange race still had its own ResolveQuery task running
  in the background, executing Open/HasViewServerState/Close against the
  caller's own connection. Meanwhile the caller proceeded to Execute against
  that same connection, producing "The connection is closed" (production)
  or "does not support MultipleActiveResultSets" (local) errors.

  Serialize ResolveQuery with a SemaphoreSlim so at most one caller ever
  runs it. Strengthen ConcurrencyTests to use closed connections, a
  synchronous barrier on dedicated threads, and 20 iterations — reliably
  reproduces the race on the old code.
@SimonCropp SimonCropp added this to the 8.1.1 milestone Apr 21, 2026
@SimonCropp SimonCropp merged commit 21d2ba1 into main Apr 21, 2026
2 of 4 checks passed
@SimonCropp SimonCropp deleted the Fix-connection-race-in-concurrent-GetLastTimeStamp branch April 21, 2026 22:30
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.

1 participant