简体   繁体   中英

Figuring out what's wrong with Heroku applications

I just created a web application and i just pushed it to heroku (it is the first time i play around with heroku).

I uploaded just fine and the index page loads, but then i get an error.

My web application consists of rendering a form, then getting the POST data and submitting it to an asynchronous function that spawns puppeteer.

When the function ends it has two choices. Running .then() which suggets the function succedeed and prompting the user with a download.

Or running .catch() which means the function failed, and it will render an error page.

In my local tests, in NEVER fails. The only way to make it fail, is to close the console (pressing the X button in the GUI).

In heroku, the page loads, i do the post and i am shown the error page. Which means the asynchronous function failed and i get the .catch() portion.

So since this function never fails in my local machine, how can i figure out what's wrong? Is there some debugging that can be done in heroku?

Or maybe shall i contact customer suuport.

I also have to note that this is a free upload. I am guessing maybe it is a memory issue?

EDIT: As user nourza suggested, this is the log by running heroku logs -t and triggering the error:

2018-09-06T20:53:53.094525+00:00 heroku[router]: at=info method=POST path="/sc"
fwd="130.43.124.255" dyno=web.1 connect=0ms service=23ms status=200 bytes=1359 p
rotocol=http
2018-09-06T20:53:53.091659+00:00 app[web.1]: Error: Failed to launch chrome!
2018-09-06T20:53:53.091671+00:00 app[web.1]: /app/node_modules/puppeteer/.local-
chromium/linux-579032/chrome-linux/chrome: error while loading shared libraries:
 libX11-xcb.so.1: cannot open shared object file: No such file or directory
2018-09-06T20:53:53.091674+00:00 app[web.1]:
2018-09-06T20:53:53.091675+00:00 app[web.1]:
2018-09-06T20:53:53.091678+00:00 app[web.1]: TROUBLESHOOTING: https://github.com
/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
2018-09-06T20:53:53.091679+00:00 app[web.1]:
2018-09-06T20:53:53.091681+00:00 app[web.1]: at onClose (/app/node_modules/puppe
teer/lib/Launcher.js:299:14)
2018-09-06T20:53:53.091683+00:00 app[web.1]: at Interface.helper.addEventListene
r (/app/node_modules/puppeteer/lib/Launcher.js:288:50)
2018-09-06T20:53:53.091686+00:00 app[web.1]: at emitNone (events.js:111:20)
2018-09-06T20:53:53.091687+00:00 app[web.1]: at Interface.emit (events.js:208:7)

2018-09-06T20:53:53.091689+00:00 app[web.1]: at Interface.close (readline.js:368
:8)
2018-09-06T20:53:53.091690+00:00 app[web.1]: at Socket.onend (readline.js:147:10
)
2018-09-06T20:53:53.091692+00:00 app[web.1]: at emitNone (events.js:111:20)
2018-09-06T20:53:53.091694+00:00 app[web.1]: at Socket.emit (events.js:208:7)
2018-09-06T20:53:53.091696+00:00 app[web.1]: at endReadableNT (_stream_readable.
js:1064:12)
2018-09-06T20:53:53.091698+00:00 app[web.1]: at _combinedTickCallback (internal/
process/next_tick.js:138:11)
2018-09-06T20:53:53.295994+00:00 heroku[router]: at=info method=GET path="/js/bo
otstrap.min.js" 

EDIT 2: After adding the line for the puppeteer buildpack, as user nourza suggested, it still does not work. This is the new output of heroku logs -t :

2018-09-07T13:16:10.870497+00:00 app[web.1]: Error: Failed to launch chrome!
2018-09-07T13:16:10.870512+00:00 app[web.1]: [0907/131610.045486:FATAL:zygote_ho
st_impl_linux.cc(116)] No usable sandbox! Update your kernel or see https://chro
mium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.
md for more information on developing with the SUID sandbox. If you want to live
 dangerously and need an immediate workaround, you can try using --no-sandbox.
2018-09-07T13:16:10.870514+00:00 app[web.1]: #0 0x562ae7866dfc base::debug::Stac
kTrace::StackTrace()
2018-09-07T13:16:10.870516+00:00 app[web.1]: #1 0x562ae77e6150 logging::LogMessa
ge::~LogMessage()
2018-09-07T13:16:10.870518+00:00 app[web.1]: #2 0x562ae8c000c0 service_manager::
ZygoteHostImpl::Init()
2018-09-07T13:16:10.870520+00:00 app[web.1]: #3 0x562ae74d1c1e content::ContentM
ainRunnerImpl::Initialize()
2018-09-07T13:16:10.870522+00:00 app[web.1]: #4 0x562ae7506128 service_manager::
Main()
2018-09-07T13:16:10.870524+00:00 app[web.1]: #5 0x562ae74d01a1 content::ContentM
ain()
2018-09-07T13:16:10.870528+00:00 app[web.1]: #6 0x562aeb90be9d headless::(anonym
ous namespace)::RunContentMain()
2018-09-07T13:16:10.870529+00:00 app[web.1]: #7 0x562aeb90bf28 headless::Headles
sBrowserMain()
2018-09-07T13:16:10.870531+00:00 app[web.1]: #8 0x562ae75037fa headless::Headles
sShellMain()
2018-09-07T13:16:10.870533+00:00 app[web.1]: #9 0x562ae59501ac ChromeMain
2018-09-07T13:16:10.870534+00:00 app[web.1]: #10 0x7f54d8f09830 __libc_start_mai
n
2018-09-07T13:16:10.870536+00:00 app[web.1]: #11 0x562ae595002a _start
2018-09-07T13:16:10.870538+00:00 app[web.1]:
2018-09-07T13:16:10.870540+00:00 app[web.1]: Received signal 6
2018-09-07T13:16:10.870541+00:00 app[web.1]: #0 0x562ae7866dfc base::debug::Stac
kTrace::StackTrace()
2018-09-07T13:16:10.870543+00:00 app[web.1]: #1 0x562ae7866961 base::debug::(ano
nymous namespace)::StackDumpSignalHandler()
2018-09-07T13:16:10.870544+00:00 app[web.1]: #2 0x7f54dee52390 <unknown>
2018-09-07T13:16:10.870546+00:00 app[web.1]: #3 0x7f54d8f1e428 gsignal
2018-09-07T13:16:10.870548+00:00 app[web.1]: #4 0x7f54d8f2002a abort
2018-09-07T13:16:10.870549+00:00 app[web.1]: #5 0x562ae78657b5 base::debug::Brea
kDebugger()
2018-09-07T13:16:10.870551+00:00 app[web.1]: #6 0x562ae77e65b9 logging::LogMessa
ge::~LogMessage()
2018-09-07T13:16:10.870553+00:00 app[web.1]: #7 0x562ae8c000c0 service_manager::
ZygoteHostImpl::Init()
2018-09-07T13:16:10.870554+00:00 app[web.1]: #8 0x562ae74d1c1e content::ContentM
ainRunnerImpl::Initialize()
2018-09-07T13:16:10.870556+00:00 app[web.1]: #9 0x562ae7506128 service_manager::
Main()
2018-09-07T13:16:10.870557+00:00 app[web.1]: #10 0x562ae74d01a1 content::Content
Main()
2018-09-07T13:16:10.870559+00:00 app[web.1]: #11 0x562aeb90be9d headless::(anony
mous namespace)::RunContentMain()
2018-09-07T13:16:10.870561+00:00 app[web.1]: #12 0x562aeb90bf28 headless::Headle
ssBrowserMain()
2018-09-07T13:16:10.870563+00:00 app[web.1]: #13 0x562ae75037fa headless::Headle
ssShellMain()
2018-09-07T13:16:10.870564+00:00 app[web.1]: #14 0x562ae59501ac ChromeMain
2018-09-07T13:16:10.870566+00:00 app[web.1]: #15 0x7f54d8f09830 __libc_start_mai
n
2018-09-07T13:16:10.870568+00:00 app[web.1]: #16 0x562ae595002a _start
2018-09-07T13:16:10.870570+00:00 app[web.1]: r8: 00007f54d92af770  r9: 00007f54d
f3cfac0 r10: 0000000000000008 r11: 0000000000000206
2018-09-07T13:16:10.870572+00:00 app[web.1]: r12: 00007ffc93c4acd8 r13: 00000000
00000161 r14: 00007ffc93c4ace0 r15: 00007ffc93c4ace8
2018-09-07T13:16:10.870574+00:00 app[web.1]: di: 0000000000000017  si: 000000000
0000017  bp: 00007ffc93c4a820  bx: 00007ffc93c4a890
2018-09-07T13:16:10.870575+00:00 app[web.1]: dx: 0000000000000006  ax: 000000000
0000000  cx: 00007f54d8f1e428  sp: 00007ffc93c4a6e8
2018-09-07T13:16:10.870577+00:00 app[web.1]: ip: 00007f54d8f1e428 efl: 000000000
0000206 cgf: 0000000000000033 erf: 0000000000000000
2018-09-07T13:16:10.870579+00:00 app[web.1]: trp: 0000000000000000 msk: 00000000
00000000 cr2: 0000000000000000
2018-09-07T13:16:10.870581+00:00 app[web.1]: [end of stack trace]
2018-09-07T13:16:10.870582+00:00 app[web.1]: Calling _exit(1). Core file will no
t be generated.
2018-09-07T13:16:10.870584+00:00 app[web.1]:
2018-09-07T13:16:10.870586+00:00 app[web.1]:
2018-09-07T13:16:10.870587+00:00 app[web.1]: TROUBLESHOOTING: https://github.com
/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
2018-09-07T13:16:10.870589+00:00 app[web.1]:
2018-09-07T13:16:10.870590+00:00 app[web.1]: at onClose (/app/node_modules/puppe
teer/lib/Launcher.js:299:14)
2018-09-07T13:16:10.870592+00:00 app[web.1]: at Interface.helper.addEventListene
r (/app/node_modules/puppeteer/lib/Launcher.js:288:50)
2018-09-07T13:16:10.870594+00:00 app[web.1]: at emitNone (events.js:111:20)
2018-09-07T13:16:10.870596+00:00 app[web.1]: at Interface.emit (events.js:208:7)

2018-09-07T13:16:10.870597+00:00 app[web.1]: at Interface.close (readline.js:368
:8)
2018-09-07T13:16:10.870599+00:00 app[web.1]: at Socket.onend (readline.js:147:10
)
2018-09-07T13:16:10.870601+00:00 app[web.1]: at emitNone (events.js:111:20)
2018-09-07T13:16:10.870602+00:00 app[web.1]: at Socket.emit (events.js:208:7)
2018-09-07T13:16:10.870604+00:00 app[web.1]: at endReadableNT (_stream_readable.
js:1064:12)
2018-09-07T13:16:10.870606+00:00 app[web.1]: at _combinedTickCallback (internal/
process/next_tick.js:138:11)
2018-09-07T13:16:11.090206+00:00 heroku[router]: at=info method=GET path="/style
sheets/bootstrap.min.css" host=insta-ripper.herokuapp.com request_id=dff59a00-35
6d-49f4-a171-657856e671b9 fwd="130.43.124.255" dyno=web.1 connect=0ms service=17
ms status=304 bytes=239 protocol=http
2018-09-07T13:16:11.096037+00:00 heroku[router]: at=info method=GET path="/js/bo
otstrap.min.js" host=insta-ripper.herokuapp.com request_id=9cf76ded-1405-40c7-87
71-70fa342b37e3 fwd="130.43.124.255" dyno=web.1 connect=0ms service=17ms status=
404 bytes=402 protocol=http
2018-09-07T13:16:11.321014+00:00 heroku[router]: at=info method=GET path="/js/bo
otstrap.min.js" host=insta-ripper.herokuapp.com request_id=98d04e8d-2dbb-4546-89
e4-a6ae47c85831 fwd="130.43.124.255" dyno=web.1 connect=0ms service=8ms status=4
04 bytes=402 protocol=http

After following user nourza's advice (which i cannot thank enough) and adding the options:

['--no-sandbox', '--disable-setuid-sandbox'] in the puppeteer.launch() function, the app manages to run, but at some time this is rendered:

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail

So i run heroku logs --tail , and the only thing suspicious is this:

2018-09-07T17:47:27.555737+00:00 heroku[router]: at=error code=H12 desc="Request
 timeout" method=POST path="/sc" request_id=21e8b890-4072-426e-bac3-91c3646a0301 fwd="130.43.124.255" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http

The server seems to break down at this code:

var fileContents = Buffer.from(result, 'ascii');
var readStream = new stream.PassThrough();
readStream.end(fileContents);
res.set('Content-disposition', 'attachment; filename=' + fileName);
res.set('Content-Type', 'text/plain');
readStream.pipe(res);

Which is a way to make the user download a part of memory as a .txt file.

Check this link Error while excuting chrome without headless on heroku

You need to include the Puppeteer Heroku buildpack to the list of buildpacks for your app. Go to your Heroku dashboard and open your app. Go to Settings > Buildpacks > Add buildpack and use this URL.

https://github.com/jontewks/puppeteer-heroku-buildpack When you click add buildpack, simply paste that URL into the input, and click save. On the next deploy, your app will also install the dependencies that Puppeteer needs to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM