mysqljs/mysql

PROTOCOL_CONNECTION_LOST while streaming

Open

#1,892 建立於 2017年12月6日

在 GitHub 查看
 (8 留言) (1 反應) (0 負責人)JavaScript (18,137 star) (2,502 fork)batch import
help wanted

描述

The issue is the same #566 It has been marked as closed but the problem is still here I am using node 0.12.18 with mysqljs 2.15.0

We have the database with 1.5kk rows in someTable and the following code with long async result handler:

var db = mysql.createConnection(dbConf);
var q = db.query("SELECT * FROM someTable");
var count = 0;

q.on("end", done);
q.on("error", function (err) {console.error(err.stack || err);});

q.on("result", function (row) {
    console.log("row:", ++count, row.id);
    db.pause()

    setTimeout(function () {
        db.resume();
    }, 1000);
});

The script fails in about 15 minutes with error PROTOCOL_CONNECTION_LOST on processing ~900 row.

The cause of this error can be revealed by tcpdump. Try to monitor all traffic between your script and the database server in real-time. The server will finish to transfer data in about 5 minutes. The db.pause()/db.resume() calls do not affect it. The server's response will be buffered by driver and will wait for processing by "long async result handler". Meanwhile the server itself will be idle and after inactivity timeout (10 minutes) will close the connection.

貢獻者指南

PROTOCOL_CONNECTION_LOST while streaming · mysqljs/mysql#1892 | Good First Issue