Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions web/packages/teleterm/src/mainProcess/resolveNetworkAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function waitForMatchInStdout(
const removeListeners = () => {
process.stdout.off('data', findAddressInChunk);
process.off('error', rejectOnError);
process.off('exit', rejectOnExit);
process.off('close', rejectOnClose);
clearTimeout(timeout);
};

Expand All @@ -97,14 +97,14 @@ function waitForMatchInStdout(
removeListeners();
};

const rejectOnExit = (code: number, signal: NodeJS.Signals) => {
const rejectOnClose = (code: number, signal: NodeJS.Signals) => {
const codeOrSignal = [
// code can be 0, so we cannot just check it the same way as the signal.
code != null && `code ${code}`,
signal && `signal ${signal}`,
]
.filter(Boolean)
.join(' and ');
.join(' ');
const details = codeOrSignal ? ` with ${codeOrSignal}` : '';
rejectOnError(
new ResolveError(
Expand All @@ -117,7 +117,11 @@ function waitForMatchInStdout(

process.stdout.on('data', findAddressInChunk);
process.on('error', rejectOnError);
process.on('exit', rejectOnExit);
// Listen for close instead of exit. This doesn't make much difference in prod usage, but it's
// meaningful in tests. testProcess.mjs exits soon after printing to stdout, so we have to make
// sure that stdio streams are closed to avoid process.on('exit') being processed before
// stdout.on('data').
process.on('close', rejectOnClose);
});
}

Expand Down