Skip to content

Commit f79e14c

Browse files
authored
Fix #1870: TypeError in PubSub (#2016)
* Fix #1870: TypeError in PubSub * Add test This test is for a race condition; it should reliably pass now, but is not guaranteed to fail with the previous version.
1 parent 8858604 commit f79e14c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/client/lib/client/commands-queue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ export default class RedisCommandsQueue {
369369
#setReturnBuffers() {
370370
this.#parser.setReturnBuffers(
371371
!!this.#waitingForReply.head?.value.returnBuffers ||
372-
!!this.#pubSubState?.subscribed
372+
!!this.#pubSubState?.subscribed ||
373+
!!this.#pubSubState?.subscribing
373374
);
374375
}
375376

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,21 @@ describe('Client', () => {
683683
}
684684
}, GLOBAL.SERVERS.OPEN);
685685

686+
testUtils.testWithClient('should not fail when message arrives right after subscribe', async publisher => {
687+
const subscriber = publisher.duplicate();
688+
689+
await subscriber.connect();
690+
691+
try {
692+
await assert.doesNotReject(Promise.all([
693+
subscriber.subscribe('channel', () => {}),
694+
publisher.publish('channel', 'message')
695+
]));
696+
} finally {
697+
await subscriber.disconnect();
698+
}
699+
}, GLOBAL.SERVERS.OPEN);
700+
686701
testUtils.testWithClient('should be able to quit in PubSub mode', async client => {
687702
await client.subscribe('channel', () => {
688703
// noop

0 commit comments

Comments
 (0)