File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
packages/redis-worker/src/fair-queue Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -101,12 +101,17 @@ export class WorkerQueueManager {
101101 // This is required because BLPOP blocks the connection
102102 const blockingClient = this . redis . duplicate ( ) ;
103103
104+ // Define cleanup outside try so it's accessible in finally
105+ // This prevents listener accumulation on the AbortSignal
106+ const cleanup = signal
107+ ? ( ) => {
108+ blockingClient . disconnect ( ) ;
109+ }
110+ : null ;
111+
104112 try {
105113 // Set up abort handler
106- if ( signal ) {
107- const cleanup = ( ) => {
108- blockingClient . disconnect ( ) ;
109- } ;
114+ if ( signal && cleanup ) {
110115 signal . addEventListener ( "abort" , cleanup , { once : true } ) ;
111116
112117 if ( signal . aborted ) {
@@ -143,6 +148,11 @@ export class WorkerQueueManager {
143148
144149 throw error ;
145150 } finally {
151+ // Always remove the listener to prevent accumulation on the AbortSignal
152+ // (once: true only removes if abort fires, not on normal completion)
153+ if ( cleanup && signal ) {
154+ signal . removeEventListener ( "abort" , cleanup ) ;
155+ }
146156 await blockingClient . quit ( ) . catch ( ( ) => {
147157 // Ignore quit errors (may already be disconnected)
148158 } ) ;
You can’t perform that action at this time.
0 commit comments