Skip to content

Commit 90f8fe9

Browse files
florian-schunkrummatee
authored andcommitted
pass abort signal
1 parent 889b56d commit 90f8fe9

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
@@ -263,6 +263,23 @@ describe('Client', () => {
263263
AbortError
264264
);
265265
}, GLOBAL.SERVERS.OPEN);
266+
267+
testUtils.testWithClient('AbortError with timeout', client => {
268+
const controller = new AbortController();
269+
controller.abort();
270+
271+
return assert.rejects(
272+
client.sendCommand(['PING'], {
273+
abortSignal: controller.signal
274+
}),
275+
AbortError
276+
);
277+
}, {
278+
...GLOBAL.SERVERS.OPEN,
279+
clientOptions: {
280+
commandTimeout: 50,
281+
}
282+
});
266283
});
267284

268285
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
@@ -896,9 +896,16 @@ export default class RedisClient<
896896
let controller: AbortController;
897897
if (this._self.#options?.commandTimeout) {
898898
controller = new AbortController()
899+
let abortSignal = controller.signal;
900+
if (options?.abortSignal) {
901+
abortSignal = AbortSignal.any([
902+
abortSignal,
903+
options.abortSignal
904+
]);
905+
}
899906
options = {
900907
...options,
901-
abortSignal: controller.signal
908+
abortSignal
902909
}
903910
}
904911
const promise = this._self.#queue.addCommand<T>(args, options);

0 commit comments

Comments
 (0)