RethinkDB:​​RqlDriverError:握手超时错误

时间:2014-12-14 15:14:02

标签: rethinkdb

我得到:RqlDriverError:每隔一段时间握手timedout错误会锁定我的群集。

错误堆栈是:

{ 
  "date": "Sun Dec 14 2014 07:59:14 GMT+0000 (Coordinated Universal Time)", 
  "process": { 
    "pid": 10664, 
    "uid": null, 
    "gid": null, 
    "cwd": "D:\\home\\site\\wwwroot", 
    "execPath": "D:\\Program Files (x86)\\nodejs\\0.10.32\\node.exe", 
    "version": "v0.10.32", 
    "argv": [ 
      "node.exe", 
      "D:\\home\\site\\wwwroot\\server.js" 
    ], 
    "memoryUsage": { 
      "rss": 31940608, 
      "heapTotal": 27892736, 
      "heapUsed": 14846880 
    } 
  }, 
  "os": { 
    "loadavg": [ 
      0, 
      0, 
      0 
    ] 
  }, 
  "trace": [ 
    { 
      "column": 13, 
      "file": "D:\\home\\site\\wwwroot\\node_modules\\rethinkdb\\errors.js", 
      "function": "new RqlDriverError", 
      "line": 14, 
      "method": null, 
      "native": false 
    }, 
    { 
      "column": 36, 
      "file": "D:\\home\\site\\wwwroot\\node_modules\\rethinkdb\\net.js", 
      "function": "null._onTimeout", 
      "line": 490, 
      "method": "_onTimeout", 
      "native": false 
    }, 
    { 
      "column": 15, 
      "file": "timers.js", 
      "function": "Timer.listOnTimeout [as ontimeout]", 
      "line": 112, 
      "method": "listOnTimeout [as ontimeout]", 
      "native": false 
    } 
  ], 
  "stack": [ 
    "RqlDriverError: Handshake timedout", 
    "    at new RqlDriverError (D:\\home\\site\\wwwroot\\node_modules\\rethinkdb\\errors.js:14:13)", 
    "    at null._onTimeout (D:\\home\\site\\wwwroot\\node_modules\\rethinkdb\\net.js:490:36)", 
    "    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)" 
  ], 
  "level": "error", 
  "message": "uncaughtException: Handshake timedout", 
  "timestamp": "2014-12-14T07:59:14.810Z" 
} 

我在请求开始时打开连接,然后在结束时关闭。 我使用以下方法打开连接:

function createConnection(req, res, next) { 
    r.connect( 
        { 
            host: 'myhost', 
            db: 'mydb', 
            authKey: 'mykey' 
        }, function(err, conn) { 
        if (err) { 
            throw err; 
        } 
        else { 
            // Save the connection in `req` 
            req.conn = conn; 
            _conn = req.conn; 
            // Pass the current request to the next middleware 
            next(); 
        } 
    }); 
} 
app.use(createConnection); 

以及处理完路线后的以下内容

function closeConnection(req, res, next) { 
    if(req.conn){ 
        req.conn.close(); 
    } 
    next(); 
} 
app.use(closeConnection); 

这是管理连接的最佳方式吗?我如何跟踪此错误的更多详细信息。

1 个答案:

答案 0 :(得分:1)

您假设使用错误调用next而不是仅仅抛出错误。 您还需要绑定连接上的侦听器并侦听"错误"事件

如果您不想处理,可以使用连接池,周围有几个库。您还可以使用具有自动池的rethinkdbdash(您不必获取和释放连接,因此不需要中间件)。