bjrmatos / jsreport-electron-pdf

jsreport recipe which renders pdf from html using electron :rocket:
MIT License
53 stars 6 forks source link

Electron-PDF timing out and looks like configuration isn't picking up from jsreport.config.json #18

Closed jLouzado closed 6 years ago

jLouzado commented 6 years ago

Issue

Steps

"dependencies": {
    "electron": "^2.0.5",
    "install": "^0.12.1",
    "jsreport": "2.1.1",
    "jsreport-electron-pdf": "^3.0.0",
    "jsreport-phantom-pdf": "^2.1.3",
    "npm": "^6.2.0"
  }
"extensions": {
    "authentication": {
      "cookieSession": {
        "secret": "some secret"
      },
      "admin": {
        "username": "some name",
        "password": "some password"
      },
      "enabled": true
    },
    "scripts": {
      "timeout": 40000,
      "strategy": "http-server"
    },
    "electron":{
      "strategy":"electron-ipc",
      "pingTimeout":100,
      "timeout":5000
    }
  },

Description

2018-07-15T10:59:39.982Z - info: Using extension electron-pdf
  electron-html-to Creating a new conversion function with options: +0ms { timeout: 10000,
  numberOfWorkers: 2,
  chromeCommandLineSwitches: { 'ignore-certificate-errors': null },
  allowLocalFilesAccess: false,
  maxLogEntrySize: 1000,
  tmpDir: '/tmp/jsreport/autocleanup',
  strategy: 'dedicated-process' }
2018-07-15T11:00:11.394Z - debug: Electron Pdf recipe start.
  electron-html-to:conversion generating new conversion task.. +31s
  electron-html-to:conversion conversion task id: ea778c01-9b8d-4672-865a-ee5c18cb5328 +0ms
  electron-html-to:conversion creating temporal html files in /tmp/jsreport/autocleanup.. +1ms
  electron-html-to:conversion creating temporal html file [type: html] in /tmp/jsreport/autocleanup/ea778c01-9b8d-4672-865a-ee5c18cb5328html.html.. +0ms
  electron-html-to:conversion starting conversion task [strategy:dedicated-process][task id:ea778c01-9b8d-4672-865a-ee5c18cb5328] with options: +1ms { browserWindow: 
   { width: undefined,
     height: undefined,
     webPreferences: { javascript: true } },
  waitForJSVarName: 'JSREPORT_READY_TO_START',
  collectLogs: true,
  delay: undefined,
  waitForJS: false,
  converterPath: '/home/ubuntu/jsreportapp/node_modules/electron-html-to/lib/converters/pdf.js',
  pdf: 
   { marginsType: undefined,
     pageSize: undefined,
     printBackground: true,
     landscape: false },
  htmlFile: '/tmp/jsreport/autocleanup/ea778c01-9b8d-4672-865a-ee5c18cb5328html.html',
  url: 'file:///tmp/jsreport/autocleanup/ea778c01-9b8d-4672-865a-ee5c18cb5328html.html',
  chromeCommandLineSwitches: { 'ignore-certificate-errors': null },
  extraHeaders: {},
  output: 
   { tmpDir: '/tmp/jsreport/autocleanup',
     id: 'ea778c01-9b8d-4672-865a-ee5c18cb5328' } }
  electron-html-to:dedicated-process-strategy saving settings in temporal file.. +1ms
  electron-html-to:dedicated-process-strategy searching electron executable path.. +0ms
  electron-html-to:dedicated-process-strategy trying to get electron path from "electron" module.. +0ms
  electron-html-to:dedicated-process-strategy spawning new electron process with args: +1ms [ '/home/ubuntu/jsreportapp/node_modules/electron-html-to/lib/scripts/standaloneScript.js' ] and options: { env: 
   { ELECTRON_WORKER_ID: 'ea778c01-9b8d-4672-865a-ee5c18cb5328',
     ELECTRON_HTML_TO_SETTINGS_FILE_PATH: '/tmp/jsreport/autocleanup/ea778c01-9b8d-4672-865a-ee5c18cb5328settings.html',
     DISPLAY: 'localhost:10.0' },
  stdio: [ null, null, null, 'ipc' ] }
  electron-html-to:dedicated-process-strategy electron process pid: +4ms 2196
  electron-html-to:dedicated-process-strategy processing conversion.. +1ms
  electron-html-to:dedicated-process-strategy electron process exit with code: 127 and signal: null +1ms
  electron-html-to:dedicated-process-strategy conversion timeout.. +10s
2018-07-15T11:00:21.409Z - error: Error when processing render request Timeout when executing in electron Error: Timeout when executing in electron
    at Timeout._onTimeout (/home/ubuntu/jsreportapp/node_modules/electron-html-to/lib/dedicatedProcessStrategy.js:277:20)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)
2018-07-15T11:00:21.410Z - error: Error during processing request at http:/<IP_Address>:5488/api/report/student-list-normal-marks
bjrmatos commented 6 years ago

hi @jLouzado, i see that there was a mistake in electron docs, the correct for configuration in extensions object should be electron-pdf, not electron, docs have been updated to fix the problem. your configuration should look like this:

"extensions": {
    "authentication": {
      "cookieSession": {
        "secret": "some secret"
      },
      "admin": {
        "username": "some name",
        "password": "some password"
      },
      "enabled": true
    },
    "scripts": {
      "timeout": 40000,
      "strategy": "http-server"
    },
    "electron-pdf":{
      "strategy":"electron-ipc",
      "pingTimeout":100,
      "timeout":5000
    }
  },

for your timeout problem it seems that it is related to electron issues with linux, electron does not run by default on linux machines, it needs to use Xvfb along with your app to be able to work (it is mentioned in installation notes). are you using Xvfb already? i see in you electron docs that the env var DISPLAY is defined, are you defining that env var in some way?, i see that it contains a value of localhost:10.0 i have never used a value like that in the past so i'm not sure if that is a valid value, most common value for env var DISPLAY i have saw is :99 (without localhost) but it really depends on how you start Xvfb in your server.

we have a docker image that has been configured to setup and start Xvfb properly, maybe it can help you. you can find how to install Xvfb and other required deps for electorn in linux here and to start it, here.

as you can see, to be able to run electron in linux is not that easy, so that is why we provide and in most cases recommend the usage of our jsreport full docker image which is configured to handle all of this.

jLouzado commented 6 years ago

Thank you @bjrmatos I'll take a look at the jsreport docker image and thank you for updating the documentation. My team decided to restyle the reports using chrome-pdf since we were on a deadline, but for next time I'll keep in mind that I'll need to configure electron a particular way.

Oh and I think the $DISPLAY value is because I was running jsreport on an AWS instance that I'd ssh'd into with the -X x-forwarding flag enabled. That's probably what caused it. Next time I'll ssh into it without activating that and see what happens.

Thank you for all your help, should I close this issue for now? Can reopen it later if I have any follow-up issues. :pray:

bjrmatos commented 6 years ago

Can reopen it later if I have any follow-up issues.

sure!! you are welcome 😃