File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
packages/redis-worker/src/fair-queue Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -788,15 +788,17 @@ export class FairQueue<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
788788 // When there's work, immediately process the next batch
789789 if ( ! hadWork ) {
790790 await new Promise < void > ( ( resolve , reject ) => {
791- const timeout = setTimeout ( resolve , this . consumerIntervalMs ) ;
792- this . abortController . signal . addEventListener (
793- "abort" ,
794- ( ) => {
795- clearTimeout ( timeout ) ;
796- reject ( new Error ( "AbortError" ) ) ;
797- } ,
798- { once : true }
799- ) ;
791+ const abortHandler = ( ) => {
792+ clearTimeout ( timeout ) ;
793+ reject ( new Error ( "AbortError" ) ) ;
794+ } ;
795+ const timeout = setTimeout ( ( ) => {
796+ // Must remove listener when timeout fires, otherwise listeners accumulate
797+ // (the { once: true } option only removes on abort, not on timeout)
798+ this . abortController . signal . removeEventListener ( "abort" , abortHandler ) ;
799+ resolve ( ) ;
800+ } , this . consumerIntervalMs ) ;
801+ this . abortController . signal . addEventListener ( "abort" , abortHandler , { once : true } ) ;
800802 } ) ;
801803 }
802804 }
You can’t perform that action at this time.
0 commit comments