jsreport / jsreport-dotnet

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

JsReport Issue after deployed on Openshift #67

Open AyagoleSneha opened 1 year ago

AyagoleSneha commented 1 year ago

Used Jsreport for converting htmltopdf in .Net Core when deployed on openshift getting Below Error 1. Exception: Error rendering report: An error ocurred while trying to execute \"render\" command (3)(because) a critical error occurred while trying to execute the render command (2)(because) an error occurred while trying to start daemonized process: An error has occurred when trying to initialize jsreport (1)-- error (1) ---> meta = {\"code\":\"WORKER_TIMEOUT\"}-> stackError: An error has occurred when trying to initialize jsreport at Object. (/snapshot/jsreport/packages/jsreport-cli/lib/keepAliveProcess.js:157:27) at Object.listener (/snapshot/jsreport/node_modules/eventemitter2/lib/eventemitter2.js:251:10) at Object.emit (/snapshot/jsreport/node_modules/eventemitter2/lib/eventemitter2.js:339:22) at Object._onData (/snapshot/jsreport/node_modules/nssocket/lib/nssocket.js:454:8) at Lazy. (/snapshot/jsreport/node_modules/lazy/lazy.js:91:13) at Lazy. (/snapshot/jsreport/node_modules/lazy/lazy.js:73:19) at Lazy.emit (node:events:390:28) at Lazy. (/snapshot/jsreport/node_modules/lazy/lazy.js:74:22) at Lazy.emit (node:events:390:28) at yieldTo (/snapshot/jsreport/node_modules/lazy/lazy.js:181:18)Remote Instance Error: Error: at /snapshot/jsreport/packages/jsreport-cli/lib/instanceHandler.js:31:29 at runNextTicks (node:internal/process/task_queues:61:5) at listOnTimeout (node:internal/timers:526:9) at processTimers (node:internal/timers:500:7)Remote Instance Error: Error: at Timeout._onTimeout (/snapshot/jsreport/packages/advanced-workers/lib/threadWorker.js:42:23) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)wrapped by:-- error (2) ---> stackError: at onCriticalError (/snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:304:19) at /snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:258:14 at async executeCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/executeCommand.js:22:20) at async Object.handler (/snapshot/jsreport/packages/jsreport-cli/lib/commander/registerCommand.js:76:9) at async parseCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:156:3) at async startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:121:20) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3)wrapped by:-- error (3)---> stackError: at startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:127:19) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5)at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3)\nlooking for previously daemonized instance in: /tmp/jsreport/cli/wSock cwd: /app/app/jsreportthere is no previously daemonized instance in: /tmp/jsreport/cli/wSock

2.Exception: Error rendering report: rendering has finished with errors:An error ocurred while trying to execute \"render\" command (3)(because) a critical error occurred while trying to execute the render command (2)(because) timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r1022525 is guaranteed to work. (1)-- error (1) ---> stackError: at Client.render (/snapshot/jsreport/packages/nodejs-client/lib/client.js:92:17)at processTicksAndRejections (node:internal/process/task_queues:96:5) at async startRender (/snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:321:24) at async /snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:228:22 at async executeCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/executeCommand.js:22:20) at async Object.handler (/snapshot/jsreport/packages/jsreport-cli/lib/commander/registerCommand.js:76:9) at async parseCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:156:3) at async startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:121:20) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3)Remote stack: TimeoutError: at Timeout.onTimeout (/snapshot/jsreport/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:300:20) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)wrapped by:-- error (2) ---> stackError: at onCriticalError (/snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:304:19) at /snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:258:14 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async executeCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/executeCommand.js:22:20) at asyncObject.handler (/snapshot/jsreport/packages/jsreport-cli/lib/commander/registerCommand.js:76:9) at async parseCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:156:3) at async startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:121:20) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3)wrapped by:-- error (3) ---> stackError: at startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:127:19) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3)\nlooking for previously daemonized instance in: /tmp/jsreport/cli/wSock cwd: /app/app/jsreportthere is no previously daemonized instance in: /tmp/jsreport/cli/wSock cwd: /app/app/jsreportinstance has been daemonized and initialized successfully (pid: 838) "Error: Exception: at jsreport.Local.Internal.LocalUtilityReportingService.RenderAsync(String requestString, CancellationToken ct)\n

3. Exception: Error rendering report: rendering has finished with errors:An error ocurred while trying to execute \"render\" command (3)(because) a critical error occurred while trying to execute the render command (2)(because) report timeout. Last profiler operation: (recipe) chrome-pdf. You can inspect and find more details here: http://localhost:5488/studio/profiles/WpmHoCjgE5IE3Xbn (1)-- error (1) ---> stackError: at Client.render (/snapshot/jsreport/packages/nodejs-client/lib/client.js:92:17) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async startRender (/snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:321:24) at async /snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:188:24 at async executeCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/executeCommand.js:22:20) at async Object.handler (/snapshot/jsreport/packages/jsreport-cli/lib/commander/registerCommand.js:76:9) at async parseCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:156:3) at async startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:121:20) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3)Remote stack: Error: at Timeout._onTimeout (/snapshot/jsreport/packages/advanced-workers/lib/threadWorker.js:42:23) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)wrapped by:-- error (2) ---> stackError: at onCriticalError(/snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:304:19) at /snapshot/jsreport/packages/jsreport-cli/lib/commands/render.js:203:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async executeCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/executeCommand.js:22:20) at async Object.handler (/snapshot/jsreport/packages/jsreport-cli/lib/commander/registerCommand.js:76:9) at async parseCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:156:3) atasync startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:121:20) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3) at async Commander.startAndWait (/snapshot/jsreport/packages/jsreport-cli/lib/commander/index.js:260:7)wrapped by:-- error (3) ---> stackError: at startCLI (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:127:19) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async startCommand (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startCommand.js:67:5) at async startProcessing (/snapshot/jsreport/packages/jsreport-cli/lib/commander/startProcessing.js:195:3) at async Commander.startAndWait (/snapshot/jsreport/packages/jsreport-cli/lib/commander/index.js:260:7) at async /snapshot/jsreport/packages/jsreport-cli/lib/cliExtension.js:35:35\nlooking for previously daemonized instance in: /tmp/jsreport/cli/wSock cwd: /app/app/jsreportusing instance daemonized previously (pid: 838)

pofider commented 1 year ago

You can try to disable keepAlive, but not sure if that helps.

new LocalReporting().UseBinary().AsUtility().KeepAlive(false)

I'm not very familiar with OpenShist. How do you deploy there? To a VM you have full control over? Or you use some kind of PaaS where you deploy a docker container? If yes, does that container work outside OpenShift? Does the platform have some restrictions on running child programs, like headless chrome?

AyagoleSneha commented 1 year ago

-We build docker image using docker file from .net core 6.0 then the same docker image is deployed to Openshift platform container .Container does not work out side openshift platform. -To use external services we need to define in ocp policy. -Can you help use to understand how internally jsreport works to convert html to pdf. -Jsreport is using any external resources that we need to whitelist. -We have seen exceptions where logs are using localhost:5488.

-Used Below code var rs = new LocalReporting() .KillRunningJsReportProcesses() .UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? JsReportBinary.GetBinary() : jsreport.Binary.Linux.JsReportBinary.GetBinary()) .Configure(cfg => cfg.AllowedLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); var tedPdf = await rs.RenderAsync(new RenderRequest { Template = new Template { Recipe = Recipe.ChromePdf, Engine = Engine.None, Content = "Hello", Chrome = new Chrome { MarginTop = "10", MarginBottom = "10", MarginLeft = "50", MarginRight = "50" } } });

-Docker File DockerFile.txt

Let me know if you any more information.

AyagoleSneha commented 11 months ago

Any Update ?

pofider commented 11 months ago

The .net jsreport direct integration works the following. The jsreport.Binary assembly has in its manifest compiled jsreport.exe binary. When the jsreport.Local starts rendering, it takes the jsreport.exe and copy it to the temp directory. Then the jsreport.exe is used with command line arguments like described here https://jsreport.net/learn/single-file-executable The jsreport.exe during the first call extracts all needed resources to the temp directory. This includes chrome.exe.

Now there are two options.

  1. You use default keep alive optimization In this case the jsreport.exe is called with --keep-alive flag which instructs to spawn jsreport process on background and communicate with it over 5488 protocol. For spawning a background process another WinRun.exe executable is used as wrapper. You can find it in the temp directory as well. So.... You call in c# reportingService.Render and this makes the call

    jsreport.exe --keep-alive render

    This spawns a new WinRun.exe process that spawns another jsreport.exe. The background jsreport.exe is contacted using http:5488. In case you use chrome-pdf recipe the background process starts Chrome.exe which does the html -> pdf conversion. When report is done, the calling jsreport.exe is closed but the background processes jsreport.exe, WinRun.exe and Chrome.exe keeps running. Note the WinRun.exe is used only on Windows.

  2. You disable keep alive optimization In this case jsreport.exe render command is called which creates Chrome.exe process eventually. After printing is done, everything is exitted.

I am not sure if this helps. Unfortunately, I am too busy to play with OpenShift at this moment. In general, my recommendation is to use jsreport.Local primarily during development, prototyping or when you really require just one service to be deployed. Otherwise, run the jsreport as a separate service. You can find here how simple it is https://github.com/jsreport/jsreport-dotnet-example-docker-compose