【问题标题】:Python app hosted on Heroku suddenly stops working (Error Code H10)Heroku 上托管的 Python 应用程序突然停止工作(错误代码 H10)
【发布时间】:2020-06-07 01:41:39
【问题描述】:
2020-02-21T04:40:16.085005+00:00 app[web.1]: [2020-02-21 04:40:16 +0000] [4] [INFO] Using worker: sync
2020-02-21T04:40:16.090866+00:00 app[web.1]: [2020-02-21 04:40:16 +0000] [14] [INFO] Booting worker with pid: 14
2020-02-21T04:40:16.169291+00:00 app[web.1]: [2020-02-21 04:40:16 +0000] [22] [INFO] Booting worker with pid: 22
2020-02-21T04:40:16.285550+00:00 app[web.1]: [2020-02-21 04:40:16 +0000] [30] [INFO] Booting worker with pid: 30
2020-02-21T04:40:16.885772+00:00 app[web.1]: /app/.heroku/vendor/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2020-02-21T04:40:16.885794+00:00 app[web.1]: 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
2020-02-21T04:40:16.991873+00:00 app[web.1]: /app/.heroku/vendor/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2020-02-21T04:40:16.991877+00:00 app[web.1]: 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
2020-02-21T04:40:17.098026+00:00 app[web.1]: /app/.heroku/vendor/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2020-02-21T04:40:17.098028+00:00 app[web.1]: 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
2020-02-21T04:40:17.810758+00:00 heroku[router]: at=info method=GET path="/" host=overwatchperfectflex.herokuapp.com request_id=c9bde3ed-25fd-418c-a289-79185c729281 fwd="40.94.36.55" dyno=web.1 connect=1ms service=18ms status=200 bytes=3793 protocol=https
2020-02-21T04:40:18.001787+00:00 heroku[router]: at=info method=GET path="/static/index.js?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=3741ce43-7f21-4bca-9cba-c65e4b899de4 fwd="40.94.36.55" dyno=web.1 connect=0ms service=10ms status=200 bytes=4656 protocol=https
2020-02-21T04:40:17.950826+00:00 heroku[router]: at=info method=GET path="/static/style.css?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=b39fca0f-0c36-471b-8e9f-356052939856 fwd="40.94.36.55" dyno=web.1 connect=0ms service=9ms status=200 bytes=5526 protocol=https
2020-02-21T04:40:18.115039+00:00 heroku[router]: at=info method=GET path="/static/sample-screenshot.jpg?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=f2ebea0f-d94a-48b6-ab07-1e6176ea1803 fwd="40.94.36.55" dyno=web.1 connect=0ms service=12ms status=200 bytes=194538 protocol=https
2020-02-21T04:40:18.128110+00:00 heroku[router]: at=info method=GET path="/static/sample-cards-screen.jpg?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=f187f422-58fa-4c5c-bc8c-5a381b8fc0b6 fwd="40.94.36.89" dyno=web.1 connect=1ms service=14ms status=200 bytes=156857 protocol=https
2020-02-21T04:40:18.204377+00:00 heroku[router]: at=info method=GET path="/static/sample-screenshot2.jpg?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=a21db7e3-aa67-4b38-aec2-255e603592cf fwd="40.94.36.97" dyno=web.1 connect=1ms service=18ms status=200 bytes=362587 protocol=https
2020-02-21T04:40:18.257411+00:00 heroku[router]: at=info method=GET path="/" host=overwatchperfectflex.herokuapp.com request_id=a7420d52-8572-40d5-9234-2a12c90b3ab1 fwd="40.94.96.47" dyno=web.1 connect=0ms service=3ms status=200 bytes=3793 protocol=https
2020-02-21T04:40:18.554730+00:00 heroku[router]: at=info method=GET path="/static/index.js?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=ff63c23b-ee06-4fc5-b2d1-a3bc2bb1bcb8 fwd="40.94.96.47" dyno=web.1 connect=0ms service=3ms status=200 bytes=4656 protocol=https
2020-02-21T04:40:18.441184+00:00 heroku[router]: at=info method=GET path="/static/style.css?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=31d0bdc2-3a4a-470f-b077-769452833050 fwd="40.94.96.47" dyno=web.1 connect=1ms service=3ms status=200 bytes=5526 protocol=https
2020-02-21T04:40:18.730303+00:00 heroku[router]: at=info method=GET path="/static/sample-cards-screen.jpg?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=15a50040-049a-4aeb-b61e-cc0f50fbc173 fwd="40.94.96.88" dyno=web.1 connect=1ms service=14ms status=200 bytes=156857 protocol=https
2020-02-21T04:40:18.722330+00:00 heroku[router]: at=info method=GET path="/static/sample-screenshot.jpg?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=b66d1329-4ddd-476c-b8c5-fbca4817ce18 fwd="40.94.96.47" dyno=web.1 connect=0ms service=14ms status=200 bytes=194538 protocol=https
2020-02-21T04:40:18.952974+00:00 heroku[router]: at=info method=GET path="/static/sample-screenshot2.jpg?h=1575409895" host=overwatchperfectflex.herokuapp.com request_id=a4798112-a7f5-4ab7-b42e-747efa851bb9 fwd="40.94.96.98" dyno=web.1 connect=0ms service=17ms status=200 bytes=362587 protocol=https
2020-02-21T04:40:20.591308+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=overwatchperfectflex.herokuapp.com request_id=efa578d0-bf07-4915-a038-77b65598387c fwd="40.94.36.97" dyno=web.1 connect=1ms service=2ms status=404 bytes=386 protocol=https
2020-02-21T04:40:21.658366+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=overwatchperfectflex.herokuapp.com request_id=559223ab-da65-439d-b716-246b656d3eaf fwd="40.94.96.98" dyno=web.1 connect=0ms service=5ms status=404 bytes=386 protocol=https
2020-02-21T05:16:18.730746+00:00 heroku[web.1]: Idling
2020-02-21T05:16:18.734547+00:00 heroku[web.1]: State changed from up to down
2020-02-21T05:16:19.783524+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-02-21T05:16:19.801722+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [4] [INFO] Handling signal: term
2020-02-21T05:16:19.802039+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [30] [INFO] Worker exiting (pid: 30)
2020-02-21T05:16:19.802390+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [22] [INFO] Worker exiting (pid: 22)
2020-02-21T05:16:19.809300+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [14] [INFO] Worker exiting (pid: 14)
2020-02-21T05:16:19.935558+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [4] [INFO] Shutting down: Master
2020-02-21T05:16:20.000313+00:00 heroku[web.1]: Process exited with status 0
2020-02-21T17:24:37.126304+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=overwatchperfectflex.herokuapp.com request_id=21677fce-34ce-4437-94ce-31692db20bce fwd="66.249.84.169,66.102.6.200" dyno= connect= service= status=503 bytes= protocol=https
2020-02-21T17:24:52.887916+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=overwatchperfectflex.herokuapp.com request_id=cbbfe77c-8cf4-4b72-a0e2-865e644bfaa3 fwd="66.201.50.243,66.102.6.201" dyno= connect= service= status=503 bytes= protocol=http

在我的应用程序托管在 heroku 上几个月后,它在几天前随机关闭。我最近没有对代码库进行任何更改。我附上了我认为与此问题有关的相关日志。我已经完成了我的研究,如果您的应用程序没有获得足够的流量,显然 heroku 会自动执行此操作,但我认为这是错误的,因为我之前在 Heroku 上托管的项目仍然可以正常工作。

*如果在本地托管,我的应用程序可以完美运行。

【问题讨论】:

  • 当您尝试重新部署您的应用时会发生什么?
  • @GinoMempin 我尝试将其置于维护模式,重置测功机然后重新部署。没用。
  • 不起作用”是什么意思?尝试重新部署时是否收到新的错误消息?还是一段时间后它也会崩溃?此外,您的日志最后会显示“应用程序崩溃”错误。我猜,测功机关闭(如果您使用的是免费测功机,那么这应该会定期发生),然后当测功机和您的应用重新启动时发生了一些事情。
  • @GinoMempin 是的,我正在使用免费的测功机?我不明白为什么会经常发生这种情况。这是否意味着如果我想继续使用免费版本,我必须在新的 heroku 应用程序下重新部署我的应用程序,直到 dyno 失败?

标签: python heroku logging shared-hosting error-code


【解决方案1】:

第一个:

heroku[路由器]: at=error code=H10 desc="App crashed"

来自Heroku Error Code docs,H10 表示“应用崩溃”:

网络测功机崩溃或网络测功机上的启动超时将显示此 错误。

2010-10-06T21:51:10-07:00 heroku[web.1]: Process exited  
2010-10-06T21:51:12-07:00 heroku[router]: at=error code=H10 desc="App  
crashed" method=GET path="/" host=myapp.herokuapp.com fwd=17.17.17.17
dyno= connect= service= status=503 bytes= 

第二个:

您似乎在使用免费的测功机,即goes to sleep after a 30-minute period of no activity

2020-02-21T04:40:21.658366+00:00 heroku[router] ... (last access) ...  
2020-02-21T05:16:18.730746+00:00 heroku[web.1]: Idling  
2020-02-21T05:16:18.734547+00:00 heroku[web.1]: State changed from up to down  
2020-02-21T05:16:19.783524+00:00 heroku[web.1]: Stopping all processes with SIGTERM

除了购买非睡眠测功机之外,您对此无能为力。当测功机进入睡眠状态时,它会停止在该测功机上运行的所有进程,包括您的应用程序。

2020-02-21T05:16:19.783524+00:00 heroku[web.1]: Stopping all processes with SIGTERM 
2020-02-21T05:16:19.801722+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [4] [INFO] Handling signal: term  
2020-02-21T05:16:19.802039+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [30] [INFO] Worker exiting (pid: 30) 
2020-02-21T05:16:19.802390+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [22] [INFO] Worker exiting (pid: 22)  
2020-02-21T05:16:19.809300+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [14] [INFO] Worker exiting (pid: 14)  
2020-02-21T05:16:19.935558+00:00 app[web.1]: [2020-02-21 05:16:19 +0000] [4] [INFO] Shutting down: Master  
2020-02-21T05:16:20.000313+00:00 heroku[web.1]: Process exited with status 0 

现在,当 Heroku 向您的应用发送 SIGTERM 信号时,在异常终止 (SIGTERM) 和应用重启之间发生了一些事情,导致应用崩溃。也许您的应用未能处理不那么优雅的退出(例如文件 I/O、数据库连接未关闭),因此从异常状态重新启动导致它崩溃。

2020-02-21T17:24:37.126304+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=overwatchperfectflex.herokuapp.com request_id=21677fce-34ce-4437-94ce-31692db20bce fwd="66.249.84.169,66.102.6.200" dyno= connect= service= status=503 bytes= protocol=https 

所以...

*如果在本地托管,我的应用程序可以完美运行。

太棒了。

也许您还需要检查当您的应用异常终止时会发生什么。在本地运行它,然后发送相同的SIGTERM 信号。获取您应用的 PID,然后查看 How can I send a signal from a python program?

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 2017-10-27
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多