@@ -67,7 +67,6 @@ export const returnToPool = (
6767// creates a new pool of workers which use the same script
6868function createPool ( script : string , options : PoolOptions = { } , logger : Logger ) {
6969 const capacity = options . capacity || options . maxWorkers || 5 ;
70-
7170 logger . debug ( `pool: Creating new child process pool | capacity: ${ capacity } ` ) ;
7271 let destroyed = false ;
7372
@@ -144,7 +143,7 @@ function createPool(script: string, options: PoolOptions = {}, logger: Logger) {
144143 // TODO what should we do if a process in the pool dies, perhaps due to OOM?
145144 const onExit = async ( code : number ) => {
146145 if ( code !== HANDLED_EXIT_CODE ) {
147- logger . debug ( ' pool: Worker exited unexpectedly' ) ;
146+ logger . debug ( ` pool: Worker exited unexpectedly with code ${ code } ` ) ;
148147 clearTimeout ( timeout ) ;
149148
150149 // Read the stderr stream from the worked to see if this looks like an OOM error
@@ -154,22 +153,22 @@ function createPool(script: string, options: PoolOptions = {}, logger: Logger) {
154153 } ) ;
155154
156155 try {
157- for await ( const line of rl ) {
158- logger . debug ( line ) ;
159- if ( line . match ( / J a v a S c r i p t h e a p o u t o f m e m o r y / ) ) {
160- reject ( new OOMError ( ) ) ;
161-
162- killWorker ( worker ) ;
163- // restore a placeholder to the queue
164- finish ( false ) ;
165- return ;
156+ if ( worker . stderr && worker . stderr ?. readableLength > 0 ) {
157+ for await ( const line of rl ) {
158+ if ( line . match ( / J a v a S c r i p t h e a p o u t o f m e m o r y / ) ) {
159+ killWorker ( worker ) ;
160+ // restore a placeholder to the queue
161+ finish ( false ) ;
162+ reject ( new OOMError ( ) ) ;
163+ return ;
164+ }
166165 }
167166 }
168167 } catch ( e ) {
169168 // do nothing
170169 }
171- reject ( new ExitError ( code ) ) ;
172170 finish ( worker ) ;
171+ reject ( new ExitError ( code ) ) ;
173172 }
174173 } ;
175174
@@ -224,8 +223,6 @@ function createPool(script: string, options: PoolOptions = {}, logger: Logger) {
224223 worker . on ( 'exit' , onExit ) ;
225224
226225 worker . on ( 'message' , ( evt : any ) => {
227- // TODO I think here we may have to decode the payload
228-
229226 // forward the message out of the pool
230227 opts . on ?.( evt ) ;
231228
0 commit comments