Skip to content

Commit

Permalink
fix: Add catch blocks to prevent unhandled rejections (#842)
Browse files Browse the repository at this point in the history
Promises without rejection handlers, i.e. `.catch` or `try catch`, will
throw "unhandled rejection" errors, which bubble up to the worker thread
causing it to exit. This PR adds handlers to the various
`simultaneousPromises` triggered within the Executor, to avoid the
described.
  • Loading branch information
morgsmccauley authored Jun 27, 2024
1 parent d6ec411 commit e3a835b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions runner/src/indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export default class Indexer {
}, this.tracer, 'get database connection parameters');

const resourceCreationSpan = this.tracer.startSpan('prepare vm and context to run indexer code');
simultaneousPromises.push(this.setStatus(IndexerStatus.RUNNING));
simultaneousPromises.push(this.setStatus(IndexerStatus.RUNNING).catch((e: Error) => {
this.logger.error('Failed to set status to RUNNING', e);
}));
const vm = new VM({ allowAsync: true });
const context = this.buildContext(blockHeight, logEntries);

Expand All @@ -130,10 +132,14 @@ export default class Indexer {
runIndexerCodeSpan.end();
}
});
simultaneousPromises.push(this.updateIndexerBlockHeight(blockHeight));
simultaneousPromises.push(this.updateIndexerBlockHeight(blockHeight).catch((e: Error) => {
this.logger.error('Failed to update block height', e);
}));
} catch (e) {
// TODO: Prevent unnecesary reruns of set status
simultaneousPromises.push(await this.setStatus(IndexerStatus.FAILING));
simultaneousPromises.push(await this.setStatus(IndexerStatus.FAILING).catch((e: Error) => {
this.logger.error('Failed to set status to FAILING', e);
}));
throw e;
} finally {
const results = await Promise.allSettled([(this.deps.indexerMeta as IndexerMeta).writeLogs(logEntries), ...simultaneousPromises]);
Expand Down

0 comments on commit e3a835b

Please sign in to comment.