【问题标题】:Heroku Web keeps crashing (hosting an API)Heroku Web 不断崩溃(托管 API)
【发布时间】:2019-10-02 18:18:49
【问题描述】:

我正在尝试使用 Heroku 托管一个 api(使用 this 教程),但是当我将它上传到 heroku 时它一直在崩溃。我也无法使用 api 发布 GET PATCH 或任何内容。

这里是日志:

2019-09-30T01:07:09+00:00 app[api]: Build succeeded
2019-09-30T01:07:11.087893+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-09-30T01:07:14.671296+00:00 heroku[web.1]: source=web.1 dyno=heroku.147978494.47f1afa0-64a4-42ab-a289-4e26dbfb7138 sample#memory_total=28.04MB sample#memory_rss=28.04MB sample#memory_cache=0.00MB sample#memory_swap=0.00MB sample#memory_pgpgin=8074pages sample#memory_pgpgout=895pages sample#memory_quota=512.00MB
2019-09-30T01:07:14.456882+00:00 app[web.1]: MongoDB connection with retry
2019-09-30T01:07:14.69389+00:00 app[web.1]: app listening at port 3600
2019-09-30T01:07:14.741028+00:00 app[web.1]: (node:4) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2019-09-30T01:07:16.534632+00:00 app[web.1]: MongoDB is connected
2019-09-30T01:07:37.004919+00:00 heroku[web.1]: source=web.1 dyno=heroku.147978494.47f1afa0-64a4-42ab-a289-4e26dbfb7138 sample#memory_total=28.86MB sample#memory_rss=28.86MB sample#memory_cache=0.00MB sample#memory_swap=0.00MB sample#memory_pgpgin=8284pages sample#memory_pgpgout=895pages sample#memory_quota=512.00MB
2019-09-30T01:07:57.936203+00:00 heroku[web.1]: source=web.1 dyno=heroku.147978494.47f1afa0-64a4-42ab-a289-4e26dbfb7138 sample#load_avg_1m=0.49
2019-09-30T01:07:57.966933+00:00 heroku[web.1]: source=web.1 dyno=heroku.147978494.47f1afa0-64a4-42ab-a289-4e26dbfb7138 sample#memory_total=22.18MB sample#memory_rss=22.18MB sample#memory_cache=0.00MB sample#memory_swap=0.00MB sample#memory_pgpgin=9600pages sample#memory_pgpgout=3923pages sample#memory_quota=512.00MB
2019-09-30T01:08:11.321679+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-09-30T01:08:11.348573+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-09-30T01:08:11.46165+00:00 heroku[web.1]: Process exited with status 137
2019-09-30T01:08:11.523496+00:00 heroku[web.1]: State changed from starting to crashed
2019-09-30T01:08:12.977371+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users" host=castor-api-test-1.herokuapp.com request_id=b11ce11c-7934-4ee5-a9a3-cb9d70c68394 fwd="175.136.22.227" dyno= connect= service= status=503 bytes= protocol=https
2019-09-30T01:09:32.635588+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users" host=castor-api-test-1.herokuapp.com request_id=3fb433e2-13d9-4e1f-ab66-f93dd9ca86ae fwd="175.136.22.227" dyno= connect= service= status=503 bytes= protocol=https

这是什么意思?提前致谢。

【问题讨论】:

  • 欢迎来到 SO!不看代码很难说,但Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 看起来是这里的主要问题。
  • 尝试通过 heroku-forward https://artsy.github.io/blog/2012/12/13/beat-heroku-60-seconds-application-boot-timeout-with-a-proxy/987654324@的代理实现来增加超时时间

标签: node.js api heroku crash


【解决方案1】:

这里有 2 个日志行是可能的原因,首先:

2019-09-30T01:08:11.321679+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

这是 Heroku 平台引发的错误。这意味着您的应用程序启动速度不够快,或者您没有绑定到正确的端口。进一步回顾您的日志:

2019-09-30T01:07:14.69389+00:00 app[web.1]: app listening at port 3600

建议您的应用绑定到端口 3600。Heroku 要求应用绑定到由 PORT 环境变量提供的端口号,该端口号通常远高于 3600,因此看起来您绑定到了您的默认端口Web 应用服务器,这意味着 Heroku 运行时无法检测您的应用是否正在运行并准备好接收请求。对于 nodejs 服务器,这通常需要确保您在服务器启动配置中使用 app.listen(process.env.PORT)

【讨论】:

    猜你喜欢
    • 2020-09-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 2021-11-29
    相关资源
    最近更新 更多