node.js Mongodb parseError occured 导致连接断开

情况:node.js 使用原生 mongodb 依赖查询。

最近日志收到如下报错:

[2015-12-28 21:00:01.848] [ERROR] console - [Error: parseError occured]
Error: parseError occured
    at null.<anonymous> (/data/game_server_142/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:198:34)
    at emit (events.js:98:17)
    at Socket.<anonymous> (/data/game_server_142/node_modules/mongodb/lib/mongodb/connection/connection.js:411:20)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:764:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:426:10)
    at emitReadable (_stream_readable.js:422:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)

查询 mongodb 日志如下:

Mon Dec 28 21:00:00 [conn72] query game_142.player query: { ... 查询 ... } nscanned:101 nreturned:101 reslen:1374301 146ms
Mon Dec 28 21:00:01 [conn72] getmore game_142.player query: { ... 查询 ... } cursorid:5517049421632407939 nreturned:427 reslen:4201834 688ms
Mon Dec 28 21:00:01 [conn71] end connection 10.105.50.74:59131
Mon Dec 28 21:00:01 [conn72] SocketException handling request, closing client connection: 9001 socket exception [2] server [10.105.50.74:59132]
Mon Dec 28 21:00:01 [conn74] end connection 10.105.50.74:59134
Mon Dec 28 21:00:01 [conn70] end connection 10.105.50.74:59130
Mon Dec 28 21:00:01 [conn73] end connection 10.105.50.74:59133

报错之后客户端与mongodb之间的连接断开。

谷歌了不少老外的情况看到 http://stackoverflow.com/questions/19546561/node-mongodb-error-connection-closed-due-to-parseerror 这一篇的情况基本与博主碰到的情况相同。

里面提到 “The production Mongo driver throws away all errors in a catch block.” 然后后面说 node 的原生 npm 模块 mongodb 在它的 1.4 版本里面修复了这个问题。

随后检查了下 node_modules/mongodb/package.json 发现版本确实是新的,不过顺着版本思路检查,发现运维新搭的 mongod server 的版本是 2.0.x 而目前公司服务器用的 mongod 版本是 3.0.3,于是升级 mongod 之后解决了。(真是没有一点点防备啊 (╯‵□′)╯︵┻━┻)

Advertisements

2 thoughts on “node.js Mongodb parseError occured 导致连接断开

    • 有两个点,一个是说原生的 mongodb 模块在 1.4 之前是 “The production Mongo driver throws away all errors in a catch block.” 也就是隐藏了实际的报错,升级以后就可以看到真正的报错。 还有就是mongodb的版本低。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s