Opentelemetry-js: [plugin-mysql]: MaxListenersExceedWarning: Memory Leak

Created on 19 Mar 2020  路  6Comments  路  Source: open-telemetry/opentelemetry-js

What version of OpenTelemetry are you using?

0.5.0, plugin-mysql (also present in 0.4.0)

What version of Node are you using?

12.13.1

What did you do?

I'm using the plugin-mysql with a mysql pool.
After a short amount of requests with the plugin enabled, I get

(node:49932) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [Query]. Use emitter.setMaxListeners() to increase limit

Tracing the issue shows it comes from here:
https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-mysql/src/mysql.ts#L237

Without the plugin enabled, I don't have any issues.

bug

All 6 comments

looking into this

Can you give me more info like what ORM you are using if any and what your connection setup and query code looks like?

Thank you :).
No ORM. Basically just:

import mysql from 'mysql'

export const connection = mysql.createPool({
  connectionLimit: process.env.MYSQL_CONNECTION_LIMIT,
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  user: process.env.MYSQL_USER,
  password: process.env.MYSQL_PASSWORD,
  database: process.env.MYSQL_DATABASE
})

export const query = async (query, preparedParams) => {
  return new Promise((resolve, reject) => {
    connection.query(query, preparedParams, (err, result) => {
      if (err) return reject(err)
      resolve(result)
    })
  })
}

@BowlingX I think I have a fix just need reviews and I'll get it pushed asap

Just published 0.5.1 which should fix your issue. Would appreciate if you could confirm for me.

Works perfectly :) thank you.

Was this page helpful?
0 / 5 - 0 ratings