Skip to content

Commit

Permalink
fix(bundles ans-104): clean up promise try/catch PE-4306
Browse files Browse the repository at this point in the history
Try/catch in the parent thread wasn't correctly cleaning up the promise.
This would cause the next call to block indefinitely. This change also
removes the 'wait' for promise cleanup since the queue method now waits
on the promise returned from parseBundle.
  • Loading branch information
djwhitt committed Jul 27, 2023
1 parent 1cce224 commit dcdbc66
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/lib/ans-104.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
parentPort,
workerData,
} from 'node:worker_threads';
import { default as wait } from 'wait';
import * as winston from 'winston';

import * as events from '../events.js';
Expand Down Expand Up @@ -184,14 +183,7 @@ export class Ans104Parser {
try {
this.unbundlePromiseResolve = resolve;
this.unbundlePromiseReject = reject;

const log = this.log.child({ parentId });
log.debug('Waiting for previous bundle to finish...');
while (this.unbundlePromise) {
await wait(100);
}
log.debug('Previous bundle finished.');

await fsPromises.mkdir(path.join(process.cwd(), 'data/tmp/ans-104'), {
recursive: true,
});
Expand All @@ -204,7 +196,7 @@ export class Ans104Parser {
const writeStream = fs.createWriteStream(bundlePath);
pipeline(data.stream, writeStream, (error) => {
if (error !== undefined) {
this.unbundlePromiseReject?.(error);
reject(error);
this.resetUnbundlePromise();
log.error('Error writing ANS-104 bundle stream', error);
} else {
Expand All @@ -219,6 +211,7 @@ export class Ans104Parser {
});
} catch (error) {
reject(error);
this.resetUnbundlePromise();
}
},
);
Expand Down

0 comments on commit dcdbc66

Please sign in to comment.