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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxListenersExceededWarning #1733

Closed
UchihaYuki opened this issue Jul 20, 2022 · 2 comments
Closed

MaxListenersExceededWarning #1733

UchihaYuki opened this issue Jul 20, 2022 · 2 comments

Comments

@UchihaYuki
Copy link

UchihaYuki commented Jul 20, 2022

🐛 Bug Report

When I do lots of searches at the same time, I'll get the following error:

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

To Reproduce

Steps to reproduce the behavior:

Paste your code here:

const esClient = new Client({
  nodes: config.es.hosts,
  auth: {
    username: config.es.username,
    password: config.es.password,
  },
})
await Promise.all(Array(20).fill(0).map(_ => esClient.search({
  index: SENTENCES_INDEX
})))

Expected behavior

It seems the client will establish a new socket connection to elasticsearch server on every search, so the number of connections will keep going up and exceed events.EventEmitter.defaultMaxListeners. Is it possible to limit the whole connections esClient can have and reuse existing ones?

Your Environment

  • node version: v16.13.1
  • @elastic/elasticsearch version: >=8.1.0
  • os: Windows
@ftejeria
Copy link

I removed the warning by adding in the TransportRequestOptions for the signal field a new AbortController().signal;, here an example client.search( { yourQuery }, { signal: new AbortController().signal, } Any problem attached to this workaround to remove the warning ?

@JoshMock
Copy link
Member

Closing as a duplicate of elastic/elastic-transport-js#63.

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

No branches or pull requests

3 participants