Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 product-check listeners added #2224

Open
dherbolt opened this issue Apr 17, 2024 · 2 comments

Comments

@dherbolt
Copy link

Please read this entire template before posting any issue. If you ignore these instructions
and post an issue here that does not follow the instructions, your issue might be closed,
locked, and assigned the not reproducible label.

馃悰 Bug Report

The very first request executes the product check procedure. When new requests comes during this check the new product-check event listeners are added.

https://github.com/elastic/elasticsearch-js/blob/7.17/lib/Transport.js#L476

The nodeJS warning is then reported:

(node:5099) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 product-check listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:587:17)
    at EventEmitter.addListener (node:events:605:10)
    at EventEmitter.once (node:events:649:8)
    at Transport.request (/Users/daniel.herbolt/test/node_modules/es7/lib/Transport.js:476:29)
    at Client.searchApi [as search] (/Users/daniel.herbolt/test/node_modules/es7/api/api/search.js:61:25)
    at /Users/daniel.herbolt/test/event-listener.js:14:18

To Reproduce

  • tested against ES running in the Docker.

Steps to reproduce the behavior:

  1. save the code below into file event-listener.js
  2. run code node --trace-warnings ./event-listener.js

Paste your code here:

const { Client: ES7Client } = require('es7')

const elasticConn = 'http://elastic:changeme@localhost:9201'
const ES_INDEX = 'test-index'

const client7 = new ES7Client({
	nodes: elasticConn.split(','),
	suggestCompression: true,
})

const cnt = 50
async function run() {
	const res = await Promise.all(Array.from({length: cnt}, async (_) => {
		return client7.search({
			index: ES_INDEX,
			body: {size: 0},
			ignore_unavailable: true,
		})
	}))
	return res
}

run().then(async () => {
	console.log('Done.')
}).catch(async (e) => {
	console.error(e)
})

Expected behavior

Only the very first request attach the 'product-check' event listener. The others requests are queued and executed from the event handler for the first request.

Paste the results here:

Your Environment

  • node version: v18.17.1
  • @elastic/elasticsearch version: 7.17.13
  • os: Mac
  • any other relevant information
@JoshMock
Copy link
Member

Looks similar to elastic/elastic-transport-js#63, which is a long-standing issue now, but that is specific to the 8.x client and its use of Undici. Will keep this open and track separately.

In the short term, if this issue is not causing notable memory leak issues for you, you can increase max listeners globally to quiet the warnings.

@JoshMock JoshMock self-assigned this Apr 17, 2024
@sibelius
Copy link

when a new release will come up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants