Skip to content

Commit 5862b39

Browse files
florian-schunkrummatee
authored andcommitted
pass abort signal
1 parent ab4c6e6 commit 5862b39

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/client/lib/client/index.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,23 @@ describe('Client', () => {
229229
AbortError
230230
);
231231
}, GLOBAL.SERVERS.OPEN);
232+
233+
testUtils.testWithClient('AbortError with timeout', client => {
234+
const controller = new AbortController();
235+
controller.abort();
236+
237+
return assert.rejects(
238+
client.sendCommand(['PING'], {
239+
abortSignal: controller.signal
240+
}),
241+
AbortError
242+
);
243+
}, {
244+
...GLOBAL.SERVERS.OPEN,
245+
clientOptions: {
246+
commandTimeout: 50,
247+
}
248+
});
232249
});
233250

234251
testUtils.testWithClient('CommandTimeoutError', async client => {

packages/client/lib/client/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,16 @@ export default class RedisClient<
737737
let controller: AbortController;
738738
if (this._self.#options?.commandTimeout) {
739739
controller = new AbortController()
740+
let abortSignal = controller.signal;
741+
if (options?.abortSignal) {
742+
abortSignal = AbortSignal.any([
743+
abortSignal,
744+
options.abortSignal
745+
]);
746+
}
740747
options = {
741748
...options,
742-
abortSignal: controller.signal
749+
abortSignal
743750
}
744751
}
745752
const promise = this._self.#queue.addCommand<T>(args, options);

0 commit comments

Comments
 (0)