Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Node invocation timeout on startup #589

Closed
chris-herring opened this issue Jan 17, 2017 · 6 comments
Closed

Node invocation timeout on startup #589

chris-herring opened this issue Jan 17, 2017 · 6 comments

Comments

@chris-herring
Copy link

I've deployed my app to Azure and often when hitting it for the first time I get a "NodeInvocationException: The Node invocation timed out after 60000ms." exception. I've done some testing and have also hit this when deployed to IIS. I could increase the InvocationTimeoutMilliseconds property but is there a way to prevent node from 'sleeping' similar to the IIS Idle Timeout setting as I would prefer to have a faster first time load for users.

(here's the full exception)

image

@MarkPieszak
Copy link
Contributor

What errors are you seeing in the debug console in Vscode or vstudio ?
Do you have a setInterval or similar in your code?

@chris-herring
Copy link
Author

No, I don't use setInterval or similar. It's only really happens on a first load to node, not subsequent loads. It's rare I hit it locally so I can't double check the debug console right now but I don't think there's much else there of note. However here's a sample of my logs from the app deployed to IIS.

2017-01-11 10:05:14.5239|1|Microsoft.AspNetCore.Hosting.Internal.WebHost|INFO|Request starting HTTP/1.1 POST http://app:8077/Account/Login?returnurl=%2F application/x-www-form-urlencoded 278 
2017-01-11 10:05:14.5239|3|Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware|INFO|HttpContext.User merged via AutomaticAuthentication from authenticationScheme: Identity.Application. 
2017-01-11 10:05:14.5239|1|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|INFO|Executing action method App.Controllers.AccountController.Login (src) with arguments (App.ViewModels.Account.LoginViewModel, /) - ModelState is Valid 
2017-01-11 10:05:14.5749|10|Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware|INFO|AuthenticationScheme: Identity.Application signed in. 
2017-01-11 10:05:14.5749|1|App.Controllers.AccountController|INFO|User logged in. 
2017-01-11 10:05:14.5749|1|Microsoft.AspNetCore.Mvc.Internal.RedirectResultExecutor|INFO|Executing RedirectResult, redirecting to /. 
2017-01-11 10:05:14.5749|2|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|INFO|Executed action App.Controllers.AccountController.Login (src) in 52.4201ms 
2017-01-11 10:05:14.5749|2|Microsoft.AspNetCore.Hosting.Internal.WebHost|INFO|Request finished in 55.2503ms 302  
2017-01-11 10:05:14.5999|1|Microsoft.AspNetCore.Hosting.Internal.WebHost|INFO|Request starting HTTP/1.1 GET http://app:8077/   
2017-01-11 10:05:14.5999|3|Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware|INFO|HttpContext.User merged via AutomaticAuthentication from authenticationScheme: Identity.Application. 
2017-01-11 10:05:14.5999|1|Microsoft.AspNetCore.Authorization.DefaultAuthorizationService|INFO|Authorization was successful for user: chris. 
2017-01-11 10:05:14.5999|1|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|INFO|Executing action method App.Controllers.HomeController.Index (src) with arguments ((null)) - ModelState is Valid 
2017-01-11 10:05:14.6299|1|Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor|INFO|Executing ViewResult, running view at path /Views/Home/Index.cshtml. 
2017-01-11 10:05:51.8376|2|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|INFO|Executed action App.Controllers.HomeController.Index (src) in 70820.7104ms
2017-01-11 10:05:52.0446|0|Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware|ERROR|An unhandled exception has occurred while executing the request The Node invocation timed out after 60000ms.
You can change the timeout duration by setting the InvocationTimeoutMilliseconds property on NodeServicesOptions.

The first debugging step is to ensure that your Node.js function always invokes the supplied callback (or throws an exception synchronously), even if it encounters an error. Otherwise, the .NET code has no way to know that it is finished or has failed.
2017-01-11 10:05:52.2386|2|Microsoft.AspNetCore.Hosting.Internal.WebHost|INFO|Request finished in 71236.0604ms 500 text/html; charset=utf-8 
2017-01-11 10:05:52.2857|14|Microsoft.AspNetCore.Server.Kestrel|INFO|Connection id "0HL1PML4LN9NB" communication error Error -4077 ECONNRESET connection reset by peer
2017-01-11 10:05:52.2867|14|Microsoft.AspNetCore.Server.Kestrel|INFO|Connection id "0HL1PML4LN9NB" communication error Error -4077 ECONNRESET connection reset by peer
2017-01-11 10:05:52.2867|14|Microsoft.AspNetCore.Server.Kestrel|INFO|Connection id "0HL1PML4LN9NB" communication error Error -4077 ECONNRESET connection reset by peer
2017-01-11 10:05:52.2867|14|Microsoft.AspNetCore.Server.Kestrel|INFO|Connection id "0HL1PML4LN9NB" communication error Error -4077 ECONNRESET connection reset by peer
2017-01-11 10:06:14.6509|2|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|INFO|Executed action App.Controllers.HomeController.Index (src) in 60046.301ms 
2017-01-11 10:06:14.6659|0|Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware|ERROR|An unhandled exception has occurred while executing the request The Node invocation timed out after 60000ms.
You can change the timeout duration by setting the InvocationTimeoutMilliseconds property on NodeServicesOptions.

The first debugging step is to ensure that your Node.js function always invokes the supplied callback (or throws an exception synchronously), even if it encounters an error. Otherwise, the .NET code has no way to know that it is finished or has failed.

@SteveSandersonMS
Copy link
Member

Is your project based on one of the generator-aspnetcore-spa templates? If so, is it by any chance an old version that still uses asp-prerender-webpack-config in your Index.cshtml file? If you are still using asp-prerender-webpack-config, please be aware that it is very slow to start on the first hit (because it's building your app in production on the first hit) - more up-to-date templates have a different system for prebuilding the prerendering bundle during deployment, so the first hit is reliably very fast.

is there a way to prevent node from 'sleeping' similar to the IIS Idle Timeout setting as I would prefer to have a faster first time load for users

Node on its own never sleeps (and the NodeService package doesn't shut it down once it's started, except if the process has to be recycled because a source file changed, which wouldn't happen in production). If you're finding that your Node process gets shut down and has to restart, then I expect that must be because the parent (.NET) process itself is getting shut down. So it's somewhat beyond the control of any code in Node.js/NodeServices. If you keep your ASP.NET process alive, then the child Node process will stay alive too.

@chris-herring
Copy link
Author

Is your project based on one of the generator-aspnetcore-spa templates? If so, is it by any chance an old version that still uses asp-prerender-webpack-config in your Index.cshtml file?

Yes, that's what I'm using. That does sound like my issue, I'll modify my project to match the latest method when I get the chance.

Thanks

@milanm
Copy link

milanm commented Oct 16, 2017

I have the same problem. I created a Angluar 4 + ASP.NET Web core 2 project on VS2017 and it works fine on a machine where it is created. But when the repo is cloned on another machine and app is started I get this error. I tried on one more machine and it is the same error. My Index.html looks like @SteveSandersonMS

`@{
ViewData["Title"] = "Home Page";
}

Loading...

<script src="~/dist/vendor.js" asp-append-version="true"></script>

@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}`

@kulkarnisachin07
Copy link

In My case resolution was (windows machine):
Node command was already registered for exe present @ "C:\Program Files\Microsoft HPC Pack 2012\Bin".
I renamed this command and then Node command from cmd was diverted to NODE js properly.
Now SPA template runs fines on machine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants