Skip to content

Commit

Permalink
fix(worker): avoid possible hazard in closing worker
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Jan 23, 2025
1 parent 2181922 commit 0f07467
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,18 +1007,17 @@ will never work with more accuracy than 1ms. */
return this.closing;
}

await this.trace<void>(
SpanKind.INTERNAL,
'close',
this.name,
async span => {
span?.setAttributes({
[TelemetryAttributes.WorkerId]: this.id,
[TelemetryAttributes.WorkerName]: this.opts.name,
[TelemetryAttributes.WorkerForceClose]: force,
});

this.closing = (async () => {
this.closing = (async () => {
await this.trace<void>(
SpanKind.INTERNAL,
'close',
this.name,
async span => {
span?.setAttributes({
[TelemetryAttributes.WorkerId]: this.id,
[TelemetryAttributes.WorkerName]: this.opts.name,
[TelemetryAttributes.WorkerForceClose]: force,
});
this.emit('closing', 'closing queue');
this.abortDelayController?.abort();

Expand Down Expand Up @@ -1048,11 +1047,11 @@ will never work with more accuracy than 1ms. */

this.closed = true;
this.emit('closed');
})();
},
);
})();

return await this.closing;
},
);
return await this.closing;
}

/**
Expand Down

0 comments on commit 0f07467

Please sign in to comment.