找出Heroku应用程序出了什么问题

时间:2018-09-06 19:56:52

标签: javascript node.js heroku

我刚刚创建了一个Web应用程序,然后将其推送到了heroku(这是我第一次玩heroku)。

我上传得很好,并且索引页已加载,但随后出现错误。

我的Web应用程序包括呈现一个表单,然后获取POST数据并将其提交给产生伪娘的异步函数。

函数结束时有两个选择。运行表示功能成功的.then()并提示用户进行下载。

或者运行.catch()意味着函数失败,它将呈现一个错误页面。

在我的本地测试中,从不失败。使其失败的唯一方法是关闭控制台(按GUI中的X按钮)。

在heroku中,页面加载,我执行该帖子,并向我显示错误页面。这意味着异步功能失败,我得到了.catch()部分。

因此,既然此功能在我的本地计算机上永远不会失败,那么我如何找出问题所在?在heroku中可以进行一些调试吗?

或者我应该联系客户支持。

我还必须注意,这是免费上传。我猜可能是内存问题?

编辑:如用户nourza所建议,这是通过运行heroku logs -t并触发错误的日志:

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" 

编辑2:按照用户nourza的建议,在添加了puppeteer buildpack的行之后,它仍然不起作用。这是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

在遵循了nourza用户的建议(我对此表示感谢)并添加了选项之后:

['--no-sandbox', '--disable-setuid-sandbox']puppeteer.launch()函数中,该应用程序设法运行了,但有时会呈现该内容:

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

所以我运行heroku logs --tail,唯一可疑的是:

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

服务器似乎在以下代码处崩溃:

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);

通过哪种方式,用户可以将内存的一部分下载为.txt文件。

1 个答案:

答案 0 :(得分:2)

检查此链接Error while excuting chrome without headless on heroku

您需要将Puppeteer Heroku构建包包括在您应用程序的构建包列表中。转到您的Heroku仪表板并打开您的应用程序。转到“设置”>“构建包”>“添加构建包”并使用此URL。

https://github.com/jontewks/puppeteer-heroku-buildpack 单击添加buildpack时,只需将该URL粘贴到输入中,然后单击“保存”即可。在下一次部署中,您的应用还将安装Puppeteer需要运行的依赖项。