url-to-pdf-api icon indicating copy to clipboard operation
url-to-pdf-api copied to clipboard

random errors when rendering pdf from html via POST

Open faliev opened this issue 7 years ago • 20 comments

First - thank you so much for creating and working on this project.

I've deployed to Heroku. Most of the time pdf is generated, sometimes there is an error and entire node server crashes.

Here is the log: url_to_pdf_api_error-01-25-2018.log

Is there a good way to debug this problem? Currently it crashes around ~20% of the time. I was running on "hobby" initially, but had same results on 1x and 2x instance types.

faliev avatar Jan 25 '18 20:01 faliev

I'm also seeing this issue, but only under docker/linux. On the mac os host it works fine.

This seems to be an issue with downstream dependencies. If I npm shrinkwrap jimaek/url-to-pdf-api and include here, it works fine.

I've done so here: https://github.com/AudaxHealthInc/url-to-pdf-api/commit/41dc56c3c028b0dcc643cf83136e3e21b1500fd7

htmldoug avatar Jan 29 '18 00:01 htmldoug

Seems like this is the error: https://github.com/websockets/ws/issues/1256

I ended up upgrading ws ("ws": "^4.0.0"), puppeteer( "puppeteer": "^1.0.0") and looks like that solved the problem.

faliev avatar Jan 30 '18 19:01 faliev

@faliev Do you mind sharing how you upgraded "ws" to 4.0.0? I'm not very familiar with npm and puppeteer 1.0.0 is using ws 3.3.3. If I add "ws": "^4.0.0" to package.json dependencies, I get both versions in my package-lock.json, where puppeteer is still using ws 3.3.3. Thanks.

jjculber avatar Feb 01 '18 19:02 jjculber

@faliev Can you please share how did you upgrade the ws module? I am getting the same issue as @jjculber

TOPS-Aman avatar Feb 14 '18 05:02 TOPS-Aman

yeah @htmldoug or @faliev can you guys share a branch/repo where this is currently working we can fork from pretty please?

theinventor avatar Mar 02 '18 00:03 theinventor

@theinventor https://github.com/AudaxHealthInc/url-to-pdf-api/commit/41dc56c3c028b0dcc643cf83136e3e21b1500fd7 works, though that's a big hammer. @faliev's solution seems more targeted.

htmldoug avatar Mar 02 '18 21:03 htmldoug

~i tried to fix this with upgrading - i thought it worked, then i didn't, now i know upgrading the ws library and puppeteer does not actually fix this, although the error is less often that's for sure... fyi see #60~

scratch that, but the bump of ws does have to be in puppeteer itself... (unless running these iterations through newman fails over the weekend, in which case i will laugh)

eriktrom avatar Mar 03 '18 00:03 eriktrom

Same issue here. Crashes all the time when using via POST. =(

KennedyTedesco avatar Mar 12 '18 21:03 KennedyTedesco

Fork puppeteer and update it’s ws dep to v4, use that fork within this package.json. Fyi

eriktrom avatar Mar 12 '18 22:03 eriktrom

@eriktrom Good. I'll do it until we find a better approach. Thanks.

KennedyTedesco avatar Mar 12 '18 23:03 KennedyTedesco

So far so good. The app remains running without crashing it.

KennedyTedesco avatar Mar 13 '18 15:03 KennedyTedesco

@eriktrom Thanks. But i also change the waitUntil to 'networkidle2' in the pdf-core.js file

crakoucas avatar Mar 28 '18 22:03 crakoucas

@crakoucas - yeah - u can use waitUntil: 'networkidle0' as well, i don't recall the exact difference anymore, might want to double check why there are 2 values for this property... fyi

also, either way, with this puppeteer update, the logging when NODE_ENV=production is insane (seems borked, logs the source file - this doesn't happen on mac in development + http allow mode) <-- main reason i never made a pr for the changes discussed here, if someone finds the fix, this issue could be closed via easy pr (after updating puppeteer itself upstream)

eriktrom avatar Mar 28 '18 22:03 eriktrom

Puppeteer has now been upgraded to 1.6.0 in master. Also published in the demo app running in Heroku. Can someone verify if the issues are fixed?

kimmobrunfeldt avatar Aug 05 '18 10:08 kimmobrunfeldt

Would you consider adding a package-lock.json or accept a PR for this?

We had problems installing a working version due to this issue and this could be mitigated by locking the dependency versions.

dominik-bln avatar Aug 10 '18 11:08 dominik-bln

@dominik-bln yeah, definitely

kimmobrunfeldt avatar Aug 13 '18 18:08 kimmobrunfeldt

any update on this ?

Allsimon avatar Nov 21 '18 16:11 Allsimon

bump

egeersoz avatar Mar 27 '19 02:03 egeersoz

As of today I am still getting the error below as described in this issue with cf1b1b65ebe7ad73832e619f781b34684907b151 and POST:

2019-05-07T12:54:09.234201954Z events.js:183
2019-05-07T12:54:09.234227129Z       throw er; // Unhandled 'error' event
2019-05-07T12:54:09.234232336Z       ^
2019-05-07T12:54:09.234238544Z 
2019-05-07T12:54:09.234242019Z Error: read ECONNRESET
2019-05-07T12:54:09.234245079Z     at TCP.onread (net.js:622:25)

is there one of the forks being more stable?

p3k avatar May 07 '19 13:05 p3k

Puppeteer is now 1.14.0 in master, which also fixes the rendering issues with large HTML contents in body. I have no way to test if this improves these random errors. Could someone try and test?

kimmobrunfeldt avatar May 14 '19 11:05 kimmobrunfeldt