Skip to content

Commit 4d03ee9

Browse files
foriequal0mergify[bot]
authored andcommitted
Warn unexpected backtrace dumps while a node is running
1 parent ec86d63 commit 4d03ee9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/src/helper/spawn.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import * as stake from "codechain-stakeholder-sdk";
3838
import { createWriteStream, mkdtempSync, unlinkSync } from "fs";
3939
import * as mkdirp from "mkdirp";
4040
import { ncp } from "ncp";
41-
import { createInterface as createReadline } from "readline";
41+
import { createInterface as createReadline, ReadLine } from "readline";
4242
import { faucetAddress, faucetSecret } from "./constants";
4343
import { wait } from "./promise";
4444

@@ -56,7 +56,7 @@ export type ChainType =
5656
type ProcessState =
5757
| { state: "stopped" }
5858
| { state: "initializing" }
59-
| { state: "running"; process: ChildProcess }
59+
| { state: "running"; process: ChildProcess; readline: ReadLine }
6060
| { state: "stopping" }
6161
| { state: "error"; message: string; source?: Error };
6262
export class ProcessStateError extends Error {
@@ -297,7 +297,8 @@ export default class CodeChain {
297297
clearListeners();
298298
self.process = {
299299
state: "running",
300-
process: child
300+
process: child,
301+
readline
301302
};
302303
child.on("close", (code, signal) => {
303304
clearListeners();
@@ -311,6 +312,14 @@ export default class CodeChain {
311312
message: `CodeChain unexpectedly exited while running: code ${code}, signal ${signal}`
312313
});
313314
});
315+
readline.on("line", (l: string) => {
316+
if (!l.startsWith("stack backtrace:")) {
317+
return;
318+
}
319+
console.error(
320+
`CodeChain(${self.id}) unexpectedly dumped backtrace`
321+
);
322+
});
314323
resolve();
315324
}
316325
}
@@ -337,8 +346,9 @@ export default class CodeChain {
337346
} else if (this.process.state !== "running") {
338347
return reject(new ProcessStateError(this.id, this.process));
339348
}
340-
const { process: child } = this.process;
349+
const { process: child, readline } = this.process;
341350
this.process = { state: "stopping" };
351+
readline.removeAllListeners("line");
342352
child
343353
.removeAllListeners()
344354
.on("error", e => {

0 commit comments

Comments
 (0)