Skip to content

perf(client): replace per-command AbortSignal timeouts with deadline lists (backport #3618) - #3629

Merged
nkaradzhov merged 1 commit into
redis:v5.12from
nkaradzhov:backport/3618-v5.12
Nov 17, 2026
Merged

nkaradzhov merged 1 commit into
redis:v5.12from
nkaradzhov:backport/3618-v5.12

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Backports #3618 to v5.12.

On 5.12, every command with a timeout creates its own AbortSignal.timeout() and listener. Under load this costs up to half the throughput and hundreds of MB of memory. 5.x has no default command timeout, so this affects clients that set timeout and commands queued during a maintenance timeout.

command-deadlines.ts, its spec, and the 'end' handler in index.ts are the same as on master. git cherry-pick 2f1e7d9 conflicts in commands-queue.ts, because the 5.x queue has no batches, preludes or #rejectCommand, so I applied the queue changes by hand:

  • Each command's deadline goes into the queue's CommandDeadlines instead of an AbortSignal. It ends when the command is written, fails to encode, or is flushed. flushAll() and the socket's 'end' stop the timers.
  • A command moved to another queue (extractCommandsForSlots/extractAllCommands, then prependCommandsToWrite) takes its deadline with it, so it times out in its new queue. Without this, the old client's 'end' would clear the timers that the moved commands depend on.
  • An abort ends the command's deadline, and a timeout removes its abort listener. On 5.12, whichever fired second removed the node from the queue again.

5.12 has no commands-queue.spec.ts, so I added one with only the tests from #3618. One change: the merge test moves the commands with extractCommandsForSlots, because extractAllCommands on 5.12 moves only the first command (it reads current.next after remove() cleared it). That bug is out of scope here.

I ran packages/client with Node 25 against the default test image: 2182 passing, 4 pending, 1 failing. The failure is LATENCY RESET, where the server logged a latency event right after the reset. It passes on its own three times in a row.


Checklist

  • Does npm test pass with this change (including linting)? (packages/client, see above; v5.12 has no lint script, npm run build passes)
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? Not needed, no API change.

Note

Medium Risk
Changes when and how write-queue timeouts fire (including maintenance and cross-queue moves), though behavior is covered by new tests and matches prior AbortSignal validation.

Overview
Introduces CommandDeadlines, a shared timer-per-timeout-value scheduler that replaces creating an AbortSignal.timeout() (and listener) for every queued command. RedisCommandsQueue now tracks timerEntry / effectiveTimeout / wasInMaintenance, arms deadlines only while a command waits to write, and clears them on write, encode failure, abort, or flush.

Moved commands (extractCommandsForSlots / extractAllCommands → prependCommandsToWrite) keep their original expiry via detach / adoptAll. flushAll and clearDeadlinesIfEmpty (also on socket end) stop timers so closed clients are not kept alive. Maintenance timeout resets go through the same #setDeadline path and still yield CommandTimeoutDuringMaintenanceError when appropriate.

Adds command-deadlines.spec.ts and a new commands-queue.spec.ts focused on timeout and merge behavior.

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

…lists (backport redis#3618)

Every command with a timeout created its own AbortSignal.timeout() and
listener, which costs up to half the throughput under load and hundreds of
MB of memory.

The queue now keeps deadlines in CommandDeadlines: one list per timeout
value with one timer per list. The client stops the timers when the socket
ends and no command is left. Behavior and errors are unchanged.

The cherry-pick conflicts in commands-queue.ts, so the queue changes are
applied by hand to the 5.x queue:

- A command moved to another queue (cluster slot migration) takes its
  deadline with it, so it times out in its new queue.
- An abort ends the command's deadline, and a timeout removes its abort
  listener, so the second one no longer removes the node again.

commands-queue.spec.ts holds only the tests that redis#3618 added.

(cherry picked from commit 2f1e7d9)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T13:33:51.151085Z 5f0d249 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nkaradzhov
nkaradzhov merged commit 525e62c into redis:v5.12 Nov 17, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f0d249964

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

};
value.slotNumber = options?.slotNumber;

const node = this.#toWrite.add(value, options?.asap);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate timeouts before enqueueing ASAP commands

With a command already waiting to be written, submitting { asap: true, timeout: -1 } now inserts a new head before validation and removes it in the catch. DoublyLinkedList.remove() does not reset the remaining head's previous link, so if the original command is subsequently aborted or times out, the list is left with a stale tail. Adding and draining a subsequent PING then yields no command, leaving valid requests hanging. This sequence works on the parent because invalid timeouts are rejected before enqueueing. Validate first or fully restore the links on rollback.

Useful? React with 👍 / 👎.

@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 high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 5f0d249. Configure here.

current.value.slotNumber !== undefined &&
slots.has(current.value.slotNumber)
) {
CommandDeadlines.detach(current.value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Detached commands hang without adopt

Medium Severity

extractCommandsForSlots and extractAllCommands now detach a command's deadline before the move. detach takes the entry off the source timer and does not fire it later. Cluster prepends with optional chaining, so a missing destination client skips adoptAll. Those commands leave every queue with no timer, so the promises never time out or settle. Previously each command kept its own AbortSignal.timeout() and still rejected.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5f0d249. Configure here.

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