jsreport / jsreport-dotnet

jsreport .NET sdk home repository
https://jsreport.net
MIT License
63 stars 10 forks source link

"Not initialized, you need to call jsreport.init().then before rendering" message on IIS if Maximum Worker Processes is greater than 1 #60

Closed NLaszlo closed 2 years ago

NLaszlo commented 3 years ago

I'm getting this error message when I try to run my template from studio: Error: Not initialized, you need to call jsreport.init().then before rendering at Reporter.render (D:\snapshot\jsreport\node_modules\jsreport-core\lib\reporter.js:322:13) at Object.render (D:\snapshot\jsreport\node_modules\jsreport-express\lib\routes.js:42:14) at D:\snapshot\jsreport\node_modules\jsreport-express\lib\routes.js:75:22 at Layer.handle [as handle_request] (D:\snapshot\jsreport\node_modules\express\lib\router\layer.js:95:5) at next (D:\snapshot\jsreport\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\snapshot\jsreport\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request]

If I set IIS Maximum Worker Processes to 1 it works but otherwise it fails.

NLaszlo commented 3 years ago

Error: Not initialized, you need to call jsreport.init().then before rendering at Reporter.render (D:\snapshot\jsreport\node_modules\jsreport-core\lib\reporter.js:322:13) at Object.render (D:\snapshot\jsreport\node_modules\jsreport-express\lib\routes.js:42:14) at D:\snapshot\jsreport\node_modules\jsreport-templates\lib\templates.js:182:71 at Layer.handle [as handle_request] (D:\snapshot\jsreport\node_modules\express\lib\router\layer.js:95:5) at next (D:\snapshot\jsreport\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\snapshot\jsreport\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\snapshot\jsreport\node_modules\express\lib\router\layer.js:95:5) at D:\snapshot\jsreport\node_modules\express\lib\router\index.js:281:22 at param (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:354:14) at param (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:365:14) at Function.process_params (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:410:3) at next (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:275:10) at D:\snapshot\jsreport\node_modules\jsreport-express\lib\routes.js:17:5 at Layer.handle [as handle_request] (D:\snapshot\jsreport\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:317:13) at D:\snapshot\jsreport\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:335:12) at next (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:275:10) at D:\snapshot\jsreport\node_modules\jsreport-express\lib\reporter.express.js:188:5 at Layer.handle [as handle_request] (D:\snapshot\jsreport\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:317:13) at D:\snapshot\jsreport\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:335:12) at next (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:275:10) at cors (D:\snapshot\jsreport\node_modules\cors\lib\index.js:188:7) at D:\snapshot\jsreport\node_modules\cors\lib\index.js:224:17 at originCallback (D:\snapshot\jsreport\node_modules\cors\lib\index.js:214:15) at D:\snapshot\jsreport\node_modules\cors\lib\index.js:219:13 at optionsCallback (D:\snapshot\jsreport\node_modules\cors\lib\index.js:199:9) at corsMiddleware (D:\snapshot\jsreport\node_modules\cors\lib\index.js:204:7) at Layer.handle [as handle_request] (D:\snapshot\jsreport\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:317:13) at D:\snapshot\jsreport\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\snapshot\jsreport\node_modules\express\lib\router\index.js:335:12)

pofider commented 3 years ago

Could you check you use the latest version of jsreport.Binary and jsreport.Local? I'm not able to replicate this problem, although using KeepAlive(false) configuration may help you.

var rs = new LocalReporting()
    .UseBinary(JsReportBinary.GetBinary())
    .Configure(cfg =>cfg.AllowLocalFilesAccess().BaseUrlAsWorkingDirectory())
    .AsUtility()
    .KeepAlive(false)
    .Create();
AndreiLacatos commented 3 years ago

We are running JSReport inside our application as web server (initialized at app start). The issue arises when we set the number of worker processes greater than 1, because the way IIS handles them is the following: when spawning a new worker thread it calls app startup which creates a new instance of JSReport web server. If we try to access IP:JSReportPort/tempateID it gives an EPIPE: broken pipe error. Could you explain please in a couple of words how the AsUtility().KeepAlive(bool) feature works?

AndreiLacatos commented 3 years ago

Also if we try to access the studio it is stuck on loading screen and in the developer console Failed to load resource: the server responded with a status of 500 (Internal Server Error) message is displayed multiple times.

NLaszlo commented 3 years ago

I have a lot of API calls using axios in a single template script. If I comment out most of them leaving just a few it works. It also starts working after a few page refreshes but at first try it displays the error.

pofider commented 3 years ago

We are running JSReport inside our application as web server (initialized at app start), The issue arises when we set the number of worker processes greater than 1

Yes, this is problematic with starting as a web server. This means there are two processes that start jsreport on the same port and one probably fails.

Using the AsUtility() would cause jsreport to start separately on the background and there should be mutex handling there is just one instance running.

If it's an option for you, I would consider running jsreport as a completely standalone service and communicate with it from your APP using jsreport.Client.

AndreiLacatos commented 3 years ago

Thank you for the quick reply, we will have a look at it.

pofider commented 2 years ago

I've released jsreport.Binary 3.8.0 as well as the other .net sdk nugets. Please try it out and reopen the issue if you have further issues.