@@ -226,17 +226,31 @@ class EmberApp {
226226 * @param {Object } result
227227 * @return {Promise<instance> } instance
228228 */
229- visitRoute ( path , fastbootInfo , bootOptions , result ) {
229+ visitRoute ( path , fastbootInfo , bootOptions , result , destroyAppInstanceInMs ) {
230230 return this . buildAppInstance ( )
231231 . then ( instance => {
232232 result . instance = instance ;
233- result . _startDestroyTimer ( ) ;
234- registerFastBootInfo ( fastbootInfo , instance ) ;
235- return instance . boot ( bootOptions ) ;
236- } )
237- . then ( ( ) => result . instanceBooted = true )
238- . then ( ( ) => result . instance . visit ( path , bootOptions ) )
239- . then ( ( ) => fastbootInfo . deferredPromise ) ;
233+ return new Promise ( function ( resolve , reject ) {
234+ let timer ;
235+ if ( destroyAppInstanceInMs > 0 ) {
236+ // start a timer to destroy the appInstance forcefully in the given ms.
237+ // This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
238+ timer = setTimeout ( ( ) => {
239+ if ( result . _destroyAppInstance ( ) ) {
240+ reject ( new Error ( 'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms' ) ) ;
241+ }
242+ } , destroyAppInstanceInMs ) ;
243+ }
244+
245+ registerFastBootInfo ( fastbootInfo , instance ) ;
246+ instance . boot ( bootOptions )
247+ . then ( ( ) => result . instanceBooted = true )
248+ . then ( ( ) => result . instance . visit ( path , bootOptions ) )
249+ . then ( ( ) => fastbootInfo . deferredPromise )
250+ . then ( ( ) => clearTimeout ( timer ) )
251+ . then ( resolve , reject ) ;
252+ } ) ;
253+ } ) ;
240254 }
241255
242256 /**
@@ -277,9 +291,9 @@ class EmberApp {
277291
278292 let doc = bootOptions . document ;
279293
280- let result = new Result ( { doc, html, fastbootInfo, destroyAppInstanceInMs } ) ;
294+ let result = new Result ( { doc, html, fastbootInfo } ) ;
281295
282- return this . visitRoute ( path , fastbootInfo , bootOptions , result )
296+ return this . visitRoute ( path , fastbootInfo , bootOptions , result , destroyAppInstanceInMs )
283297 . then ( ( ) => {
284298 if ( ! disableShoebox ) {
285299 // if shoebox is not disabled, then create the shoebox and send API data
0 commit comments