Skip to content

refactor: remove PreExecCheck leaky abstraction and fix sync-over-async#405

Merged
currantw merged 4 commits into
valkey-io:mainfrom
currantw:refactor/remove-pre-exec-check-leaky-abstraction
May 14, 2026
Merged

refactor: remove PreExecCheck leaky abstraction and fix sync-over-async#405
currantw merged 4 commits into
valkey-io:mainfrom
currantw:refactor/remove-pre-exec-check-leaky-abstraction

Conversation

@currantw
Copy link
Copy Markdown
Collaborator

@currantw currantw commented May 14, 2026

Based on #359 (by @makubo-aws) with DCO signoff added. Closes #266.

makubo-aws and others added 4 commits May 14, 2026 09:33
ValkeyBatch.PreExecCheck() was a virtual hook that existed solely to
support transaction preconditions. Batches have no concept of
preconditions, so this was transaction-specific logic leaking into the
base class.

Additionally, ValkeyTransaction.PreExecCheck() called
ExecuteImpl().GetAwaiter().GetResult() — the last remaining
sync-over-async call in the codebase — which risks deadlocks in
environments with a synchronization context (e.g. ASP.NET).

Changes:
- Remove virtual PreExecCheck() from ValkeyBatch and the
  if (PreExecCheck()) guard from ExecuteImpl(). ExecuteImpl() now
  unconditionally executes the batch, which is the correct behaviour
  for ValkeyBatch (conditions are a transaction concern only).
- Move condition evaluation into ValkeyTransaction.ExecuteAsync()
  directly, using await instead of .GetAwaiter().GetResult().
- Short-circuit early (set _tcs result to null and return false) as
  soon as any condition fails, avoiding unnecessary work.
- Rename the inner batch variable from b to conditionBatch for clarity.

Fixes valkey-io#266

Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
…-io#402)

Signed-off-by: currantw <taylor.curran@improving.com>
… into refactor/remove-pre-exec-check-leaky-abstraction
@currantw currantw self-assigned this May 14, 2026
@currantw currantw added docs Documentation and developer guides core Core library (`sources/Valkey.Glide/`) release-1.2 Targeted for release 1.2 labels May 14, 2026
@currantw currantw requested review from alexr-bq and xShinnRyuu May 14, 2026 16:39
@currantw currantw merged commit ccfac11 into valkey-io:main May 14, 2026
22 of 24 checks passed
@currantw currantw deleted the refactor/remove-pre-exec-check-leaky-abstraction branch May 14, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core library (`sources/Valkey.Glide/`) docs Documentation and developer guides release-1.2 Targeted for release 1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Remove PreExecCheck leaky abstraction from ValkeyBatch and eliminate sync-over-async in ValkeyTransaction

4 participants