Skip to content

Prevent timed-out offline commands from replaying#2131

Open
MicroMilo wants to merge 2 commits into
redis:mainfrom
MicroMilo:codex/fix-command-timeout-offline-replay
Open

Prevent timed-out offline commands from replaying#2131
MicroMilo wants to merge 2 commits into
redis:mainfrom
MicroMilo:codex/fix-command-timeout-offline-replay

Conversation

@MicroMilo

@MicroMilo MicroMilo commented Jun 30, 2026

Copy link
Copy Markdown

Summary

This preserves the existing commandTimeout semantics as a total command lifetime timeout, including time spent waiting in the offline queue, but prevents a command that has already timed out from being replayed later when the connection becomes ready.

Fixes #2130.

Details

  • Mark rejected commands as settled so timeout rejection is a terminal command state.
  • Return early from standalone and cluster sendCommand() when the command is already settled, before queueing or writing it again.
  • Clarify the commandTimeout option docs to state that the timer starts when the command is issued and includes offline queue / reconnect wait.
  • Add a regression test with a delayed connector: the command times out while queued offline, then the connection becomes ready, and the server must not receive the already-timed-out command.

Tests

npm run build
TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test npx mocha --no-experimental-strip-types "test/functional/commandTimeout.ts"
TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test npx mocha --no-experimental-strip-types "test/unit/command.ts" "test/unit/redis.ts"

Note

Medium Risk
Touches core command lifecycle and send paths for standalone and cluster clients; behavior change is narrow (already-rejected commands) but affects reconnect/offline-queue replay semantics.

Overview
Fixes a case where a command that hit commandTimeout while sitting in the offline queue could still be sent to Redis after the connection became ready, even though the caller had already received "Command timed out".

Command now tracks isSettled as a terminal state on reject/resolve (including timeout rejection), with guards so settled commands are not resolved/rejected again. Command and blocking timeout handlers use isSettled instead of isResolved.

Redis.sendCommand and Cluster.sendCommand return the existing promise immediately when command.isSettled, so flushed/replayed offline commands are not queued or written again.

commandTimeout docs now state the timer starts when the command is issued and counts offline-queue wait. A functional test uses a delayed connector to assert the server receives no bytes after a timed-out offline set.

Reviewed by Cursor Bugbot for commit 034ebcc. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci

jit-ci Bot commented Jun 30, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f248cbb. Configure here.

Comment thread lib/Redis.ts
@PavelPashov

Copy link
Copy Markdown
Contributor

@MicroMilo Thanks for the PR. I’ll take a look and review it.

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.

commandTimeout can fire while a command is still queued offline

2 participants