File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -288,13 +288,21 @@ export class RedisConnection extends EventEmitter {
288
288
const status = this . status ;
289
289
this . status = 'closing' ;
290
290
this . closing = true ;
291
+
291
292
try {
292
293
if ( status === 'ready' ) {
293
294
// Not sure if we need to wait for this
294
295
await this . initializing ;
295
- if ( ! this . shared ) {
296
+ }
297
+ if ( ! this . shared ) {
298
+ if ( status == 'initializing' ) {
299
+ // If we have not still connected to Redis, we need to disconnect.
300
+ this . _client . disconnect ( ) ;
301
+ } else {
296
302
await this . _client . quit ( ) ;
297
303
}
304
+ // As IORedis does not update this status properly, we do it ourselves.
305
+ this . _client [ 'status' ] = 'end' ;
298
306
}
299
307
} catch ( error ) {
300
308
if ( isNotConnectionError ( error as Error ) ) {
Original file line number Diff line number Diff line change @@ -144,6 +144,20 @@ describe('connection', () => {
144
144
await worker . close ( ) ;
145
145
} ) ;
146
146
147
+ it ( 'should close underlying redis connection when closing fast' , async ( ) => {
148
+ const queue = new Queue ( 'CALLS_JOB_QUEUE_NAME' , {
149
+ connection : {
150
+ host : 'localhost' ,
151
+ port : 6379 ,
152
+ } ,
153
+ } ) ;
154
+
155
+ const client = queue [ 'connection' ] [ '_client' ] ;
156
+ await queue . close ( ) ;
157
+
158
+ expect ( client . status ) . to . be . eql ( 'end' ) ;
159
+ } ) ;
160
+
147
161
it ( 'should recover from a connection loss' , async ( ) => {
148
162
let processor ;
149
163
You can’t perform that action at this time.
0 commit comments