@@ -38,7 +38,7 @@ import * as stake from "codechain-stakeholder-sdk";
3838import { createWriteStream , mkdtempSync , unlinkSync } from "fs" ;
3939import * as mkdirp from "mkdirp" ;
4040import { ncp } from "ncp" ;
41- import { createInterface as createReadline } from "readline" ;
41+ import { createInterface as createReadline , ReadLine } from "readline" ;
4242import { faucetAddress , faucetSecret } from "./constants" ;
4343import { wait } from "./promise" ;
4444
@@ -56,7 +56,7 @@ export type ChainType =
5656type 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 } ;
6262export 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