#1535·ioredis

With commandTimeout option set, active timers are not cleared on client disconnection

Author: gregplaysguitarCreated Mar 18, 2022Updated Sep 3, 2026
Labelsbug

With the commandTimeout option set, a timer is set up here: https://github.com/luin/ioredis/blob/eabb70ed835828ad85b602a217992486e05d2218/lib/Command.ts#L292-L300

the only place this timer gets cleared is here:

https://github.com/luin/ioredis/blob/eabb70ed835828ad85b602a217992486e05d2218/lib/Command.ts#L349-L366

and that only gets called on successful resolution of the command...

https://github.com/luin/ioredis/blob/eabb70ed835828ad85b602a217992486e05d2218/lib/Command.ts#L302-L324

The result is that if the client is disconnected while there is an active command timeout, there ends up being an orphaned timer in the nodejs process. In my case, this is causing tests and lambda executions to hang until the timer clears.

Possible simple fix is just to clear the timer on promise rejection too, here? I'm not familiar enough with the codebase to know if this is right though. If a maintainer could confirm this is a good idea, I can open a PR to implement:

https://github.com/luin/ioredis/blob/eabb70ed835828ad85b602a217992486e05d2218/lib/Command.ts#L315-L317