mysql - Node.js 内存泄漏

标签 mysql node.js

我的 node.js 应用程序出现以下错误。这是一个简单的 mysql 查询 Web 服务。我每天大约有 20,000 到 30,000 次点击,它托管在 appfog 上。我正在使用 mysql 连接池,我认为这有帮助。想法是什么导致了这个错误?一段时间后,应用程序崩溃了(404 错误),我必须重新启动它。

====> /logs/staging.log <====

# Logfile created on 2013-02-06 06:56:31 +0000 by logger.rb/25413
Installing dependencies. Node version 0.8.14
Installing mysql@mysql@2.0.0-alpha7 from local path
Installing require-all@require-all@0.0.3 from local path
Installing bignumber.js@bignumber.js@1.0.1 from local path
Installing require-all@https://registry.npmjs.org/require-all/-/require-all-0.0.5.tgz from local path
Installing request@request@ from local path
Installing form-data@form-data from local path
Installing combined-stream@combined-stream@0.0.3 from local path
Installing delayed-stream@delayed-stream@0.0.5 from local path
Installing async@async@0.1.9 from local path
Installing mime@mime from local path

====> /logs/stderr.log <====

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Connection.EventEmitter.addListener (events.js:175:15)
    at handleDisconnect (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:75:28)
    at /mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:93:13
    at Pool.getConnection (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/Pool.js:25:5)
    at QueryDB (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:73:14)
    at IncomingMessage.http.createServer.pool.getConnection.connection.on.offset (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:51:17)
    at IncomingMessage.EventEmitter.emit (events.js:93:17)
    at IncomingMessage._emitEnd (http.js:366:10)
    at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
    at Socket.socket.ondata (http.js:1704:22)
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Connection.EventEmitter.addListener (events.js:175:15)
    at handleDisconnect (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:75:28)
    at /mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:93:13
    at Pool.getConnection (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/Pool.js:25:5)
    at QueryDB (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:73:14)
    at IncomingMessage.http.createServer.pool.getConnection.connection.on.offset (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:51:17)
    at IncomingMessage.EventEmitter.emit (events.js:93:17)
    at IncomingMessage._emitEnd (http.js:366:10)
    at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
    at Socket.socket.ondata (http.js:1704:22)

====> /logs/stdout.log <====


Wed, 06 Feb 2013 07:27:13
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:34:51
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:34:51
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:39:14
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:39:14
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:41:08
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:41:08
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:43:35
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:45:10
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:47:22
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

Wed, 06 Feb 2013 07:47:22
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/node_modules/mysql/lib/protocol/Protocol.js:72:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

最佳答案

由于没有提供源代码,这实际上是一个有教育意义的猜谜游戏,所以...

at Connection.EventEmitter.addListener (events.js:175:15)
at handleDisconnect (/mnt/var/vcap.local/dea/apps/ta-0-887f6653d9e54cd272cde95a0954869b/app/app.js:75:28)

我的猜测是,您在“handleDisconnect”函数中有一些代码,通过创建/绑定(bind)新事件来生成泄漏“addLister”。

关于mysql - Node.js 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14733361/

相关文章:

Mysql 启动失败,出现操作系统错误 13

php - 试图设置 session 变量

php - html 刷新基于 php 变量

MySQL COALESCE 函数无法返回非空值

javascript - 如何在 app.get() 中将 $and 值从 getcondition 返回到 options.where?

node.js - 文件不会从 Amazon S3 中删除

node.js - 当我运行 npm i 或安装时出现此错误,如何修复?

c# - 程序不允许我使用 MySQL 的 .net 连接器更新 SQL 服务器中的日期时间列

node.js - Node JS 回调同步执行

node.js - node.js Redis包更新是否清除Redis数据库?