88 */
99
1010var async = require ( 'async' ) ;
11- var shellFork = require ( 'child_process' ) . fork ;
11+ var fork = require ( 'child_process' ) . fork ;
1212var request = require ( 'supertest' ) ;
1313var restify = require ( 'restify' ) ;
1414var url = require ( 'url' ) ;
@@ -39,7 +39,7 @@ module.exports = function(hydraterFunction, logger, errLogger) {
3939
4040 async . waterfall ( [
4141 function performHydration ( cb ) {
42- var child = shellFork ( __dirname + '/child-process.js' , { silent : true } ) ;
42+ var child = fork ( __dirname + '/child-process.js' , { silent : true } ) ;
4343 var stderr = "" ;
4444 var stdout = "" ;
4545 var timeout ;
@@ -81,7 +81,7 @@ module.exports = function(hydraterFunction, logger, errLogger) {
8181 } ) ;
8282
8383 child . on ( 'exit' , function ( errCode ) {
84- if ( errCode !== 0 ) {
84+ if ( errCode !== 0 && errCode !== 143 ) {
8585 cleaner ( new HydrationError ( "Child exiting with err code: " + errCode + stdout + stderr ) ) ;
8686 }
8787 } ) ;
@@ -110,7 +110,7 @@ module.exports = function(hydraterFunction, logger, errLogger) {
110110 if ( err && err . _hydrationError ) {
111111 res . changes = { } ;
112112 res . changes . hydration_errored = true ;
113- res . changes . hydration_error = res . err . message ;
113+ res . changes . hydration_error = err . message ;
114114 err = null ;
115115 }
116116 cleaner ( err , res . changes ) ;
@@ -121,8 +121,14 @@ module.exports = function(hydraterFunction, logger, errLogger) {
121121 var changes = { } ;
122122 changes . hydration_errored = true ;
123123 changes . hydration_error = "Task took too long." ;
124- child . kill ( 'SIGKILL' ) ;
125- cleaner ( null , changes ) ;
124+ errLogger ( 'Killing task: ' + ( ( task . file_path ) ? task . file_path : task . document . id ) ) ;
125+ child . kill ( 'SIGTERM' ) ;
126+ setTimeout ( function ( ) {
127+ if ( child . connected ) {
128+ child . kill ( 'SIGKILL' ) ;
129+ }
130+ cleaner ( null , changes ) ;
131+ } , process . env . TIMEOUT / 6 || 10 * 1000 ) ;
126132 }
127133 } , process . env . TIMEOUT || 60 * 1000 ) ;
128134 } ,
0 commit comments