Init problem with iisnode and jsreport 2.1.0



  • Hi,

    i have the problem that the first Request to the Reportserver after the website is started always fails with this Error:
    Not initialized, you need to call jsreport.init().then before rendering

    This is my server.js:

    var jsreport = require('jsreport')()
    
    jsreport.init().then(function () 
    {
    	// running
    	console.log ("jsreport initialized")
    }).catch(function (e) 
    {
    	// error during startup
    	console.error(e.stack)
    	process.exit(1)
    })
    

    All following requests are ok.
    So the problem seems to be, that after Applikation start the jsreport starts rendering before the initialisation is complete.

    How can i fix this problem?



  • I am not an expert on iis or iis node. However..
    Can't you solve it on your client side by implementing a retry policy?
    Or if you have a load balancer upfront, you could configure health checks.
    There is likely also a solution for iis directly, but I don't have experience with it.



  • The reason for this problem is that the node.exe process is not running after the IIS application pool is restartet. It gets startet when the first HTTP request arrives.

    I can see 3 possible solutions

    1. retry on error as you suggested. Disadvantage is, it has to be implemented everywhere the jsreport api is called.
    2. somehow modify the IIS configuration so the node.exe process gets startet automatically without an external request
      this is described here: https://tomasz.janczuk.org/2013/07/application-initialization-of-nodejs.html
      but so far i can't get it to work as it should.
    3. I hoped it would be possible to modify the jsreport startup so it would start rendering after init complete.
      Somehow like this (pseudo solution).
    var startoptions = {autostart:false}
    var jsreport = require('jsreport')(startoptions) // require without starting immediately
    
    jsreport.init().then(function () 
    {
    	// running
    	console.log ("jsreport initialized")
            jsreport.start() // then start after init complete
    }).catch(function (e) 
    {
    	// error during startup
    	console.error(e.stack)
    	process.exit(1)
    })
    


  • Ok I get the problem a bit more. You get this error when application pool gets recycled. I was wondering how is the chance you start web server and it gets requests at the same time.

    I think the problem can be we open the web server a millisecond before the jsreport is fully initialized.
    Normally no one bothers, just the iisnode waits for node to open web server and sends the queued request immediately.
    We will try to fix that.

    Can't you configure application pool to don't do recycles for now?
    I usually set this anyway as application pool recycling after 15 minutes idle time is annoying default behavior.
    Something like this
    https://thycotic.force.com/support/s/article/Changing-IIS-to-not-stop-worker-process-in-IIS-7-and-8

    A bit off topic, but do you need to use iisnode?
    We stopped using it long time ago and also don't recommend to use it.

    Cant you just use windows service?
    https://jsreport.net/learn/cli#-win-install-



  • Hi Jan,

    many thanks for your help.
    I think i found a solution now. The method i described as 2. works. I had to install an IIS feature to make it work.
    In case someone else is having this problem, i found the solution here:
    https://forums.iis.net/t/1237168.aspx?What+is+the+Application+Initialization+module+to+download+for+IIS+8+5+in+windows+server+2012+R2+

    About using IISNode at all: Yes i could run a service too. But i need the IIS anyway for other things and i am used to it.
    So no it is working and i will leave it this way for now.

    Thanks again for help, your support is really great!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.