search

Home  >  Q&A  >  body text

node.js - nodejs项目在heroku上跑失败,打印错误代码code=H10(内容附详细log)

heroku上web dynos是1,数据库用的是heroku中的clearDB:ignite,connection限定是10
项目在foreman start没有出现问题

最开始,项目在heroku上跑失败,然后看自己项目的代码,发现数据库配置好后,就conn.connect(),并没有做任何异常处理,于是我对数据库连接做的这样的修改:

function handleDisconnect(){

    conn = mysql.createConnection(db_config);
    conn.connect(function (err){
        if(err){
            console.log('error when connecting to db:', err);
            setTimeout(handleDisconnect, 2000);
        }
    });

    conn.on('error', function (err){
        console.log('db error', err);
        if(err.code === 'PROTOCOL_CONNECTION_LOST'){
            handleDisconnect();
        }
        else{
            throw err;
        }
    });
} 

var db_config = ({
    connectionLimit: 10,
    host: '***',
    user: '***',
    password: '***',
    database: '***'   //
});

但是还是没跑成功,贴出heroku logs

2014-11-18T13:40:25.516150+00:00 app[web.1]:   code: 'ER_USER_LIMIT_REACHED',
2014-11-18T13:40:25.516156+00:00 app[web.1]:   fatal: true }
2014-11-18T13:40:25.747226+00:00 app[web.1]:   code: 'ER_USER_LIMIT_REACHED',
2014-11-18T13:40:25.747228+00:00 app[web.1]:   errno: 1226,
2014-11-18T13:40:25.747231+00:00 app[web.1]:   sqlState: '42000',
2014-11-18T13:40:25.747233+00:00 app[web.1]:   fatal: true }
2014-11-18T13:40:25.817449+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-11-18T13:40:25.817664+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-11-18T13:40:26.637882+00:00 heroku[web.1]: Process exited with status 137
2014-11-18T13:40:26.650174+00:00 heroku[web.1]: State changed from starting to crashed
2014-11-18T13:43:19.620511+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=943cb29f-4018-47bd-abed-e8528f34463c fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T13:50:48+00:00 heroku[slug-compiler]: Slug compilation started
2014-11-18T13:50:53+00:00 heroku[slug-compiler]: Slug compilation finished
2014-11-18T13:50:53.134832+00:00 heroku[api]: Release v27 created by ybooty0@gmail.com
2014-11-18T13:50:53.134803+00:00 heroku[api]: Deploy 276bd38 by ybooty0@gmail.com
2014-11-18T13:50:53.387565+00:00 heroku[web.1]: State changed from crashed to starting
2014-11-18T13:50:55.370783+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-18T13:50:56.352391+00:00 app[web.1]: listen port:3000
2014-11-18T13:51:09.808436+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-18T13:51:10.966893+00:00 app[web.1]: listen port:3000
2014-11-18T13:51:24.749168+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-11-18T13:51:26.002004+00:00 heroku[web.1]: Process exited with status 143
2014-11-18T13:52:01.559470+00:00 app[web.1]: db error { [Error: Connection lost: The server closed the connection.] fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
2014-11-18T13:52:10.009461+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-11-18T13:52:10.011140+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-11-18T13:52:10.847913+00:00 heroku[web.1]: Process exited with status 137
2014-11-18T13:52:10.930299+00:00 heroku[web.1]: State changed from starting to crashed
2014-11-18T13:52:10.931028+00:00 heroku[web.1]: State changed from crashed to starting
2014-11-18T13:52:13.429078+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-18T13:52:14.743426+00:00 app[web.1]: listen port:3000
2014-11-18T13:53:01.585187+00:00 app[web.1]: db error { [Error: Connection lost: The server closed the connection.] fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
2014-11-18T13:53:13.738410+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-11-18T13:53:13.738618+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-11-18T13:53:14.460601+00:00 heroku[web.1]: Process exited with status 137
2014-11-18T13:53:14.471170+00:00 heroku[web.1]: State changed from starting to crashed
2014-11-18T13:53:15.702820+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=5929aba6-9e68-4364-a01b-d88276556fb5 fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T13:53:16.167433+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=224340c2-fb70-43e7-ac7d-fe48c0caa177 fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T13:53:30.184663+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=629c31ae-a003-4f71-aa57-5c48bb0834f1 fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T13:55:53+00:00 heroku[slug-compiler]: Slug compilation started
2014-11-18T13:55:59+00:00 heroku[slug-compiler]: Slug compilation finished
2014-11-18T13:55:59.596193+00:00 heroku[api]: Deploy 524c1cc by ybooty0@gmail.com
2014-11-18T13:55:59.596193+00:00 heroku[api]: Release v28 created by ybooty0@gmail.com
2014-11-18T13:55:59.803424+00:00 heroku[web.1]: State changed from crashed to starting
2014-11-18T13:56:01.628121+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-18T13:56:02.691273+00:00 app[web.1]: listen
2014-11-18T13:56:47.721732+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-18T13:56:48.569681+00:00 app[web.1]: listen
2014-11-18T13:56:48.268846+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-11-18T13:56:49.626232+00:00 heroku[web.1]: Process exited with status 143
2014-11-18T13:57:48.201967+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-11-18T13:57:48.201717+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-11-18T13:57:48.993016+00:00 heroku[web.1]: Process exited with status 137
2014-11-18T13:57:49.000428+00:00 heroku[web.1]: State changed from starting to crashed
2014-11-18T13:57:51.148935+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=b0395099-1e7d-4142-8398-9450fa927c4f fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T14:04:57.673963+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=00fac694-6521-4005-8f0e-391d26ae2990 fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T14:09:57.102273+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=haixiu-web.herokuapp.com request_id=55e99f5a-010a-428f-a408-d5c42ff46a6e fwd="106.187.36.10" dyno= connect= service= status=503 bytes=
2014-11-18T14:12:07.036105+00:00 heroku[web.1]: State changed from crashed to starting
2014-11-18T14:12:09.042086+00:00 heroku[web.1]: Starting process with command `node index.js`
2014-11-18T14:12:10.204534+00:00 app[web.1]: listen
2014-11-18T14:13:01.171295+00:00 app[web.1]: db error { [Error: Connection lost: The server closed the connection.] fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
2014-11-18T14:13:09.515324+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-11-18T14:13:09.515553+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-11-18T14:13:10.240589+00:00 heroku[web.1]: Process exited with status 137
2014-11-18T14:13:10.246122+00:00 heroku[web.1]: State changed from starting to crashed

附带说明,我做的是一个nodejs的爬虫项目,数据库中有个字段存储着爬下图片的链接;而web dyno在heroku上是这样解释 : A web dyno runs your code and responds to HTTP requests. More dynos provide more concurrency. 图片加载的时候会向原网站发送请求,这里是不是又有可能是项目失败的原因?

谦求解答,如何提问的方式有哪里不好,也请指出

阿神阿神2863 days ago830

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 11:25:30

    The problem has been solved now, please share your solution process:
    First, find the root cause of the problem yourself: cleardb:ignite This free addon provides only 10 connections, and the link established in mysql, if the pool is not used, the link cannot be established after 10 connections.
    So the problem is solved like this, use the pool and release it after each connection, so that it can be returned to the pool for reuse.
    You can refer to how to use pool in npm myslq: https://github.com/felixge/node-mysql

    reply
    0
  • Cancelreply