sidorares / sidorares/node-mysql2

Sporadically getting EventEmitter memory leak warning when using LOAD INFILE with stream

Open
#186 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

I am calling connection.query ({sql: sql, infileStreamFactory: function (){ return stream; }}) many times over the life of a connection. Each time, stream is a different object. However, I see that the warning is happening when _streamLocalInfile in query.js is attaching an event listener to connection.stream.

Perhaps there should be calls to removeListener on the connection.stream object once the localStream has ended?

Thanks

Alessandro

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Socket.addListener (events.js:160:15)
at Query._streamLocalInfile (node_modules/mysql2/lib/commands/query.js:122:21)
at Query.resultsetHeader (node_modules/mysql2/lib/commands/query.js:99:10)
at Query.Command.execute (node_modules/mysql2/lib/commands/command.js:34:20)
at Connection.handlePacket (node_modules/mysql2/lib/connection.js:310:28)
at PacketParser.onPacket (node_modules/mysql2/lib/connection.js:83:65)
at PacketParser.executeStart (node_modules/mysql2/lib/packet_parser.js:39:12)
at Socket. (node_modules/mysql2/lib/connection.js:95:31)
at Socket.emit (events.js:95:17)
at Socket. (_stream_readable.js:764:14)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in node_modules/mysql2/lib/commands/query.js at Query._streamLocalInfile and inspect how listeners are attached to connection.stream during repeated LOAD INFILE queries. Reproduce the warning with distinct infile streams over one connection, then verify the warning no longer appears after each local stream ends.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, node.js
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.