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

Memory leak warning and excessive memory usage when using ProxyAgent with signals #3946

Open
timursevimli opened this issue Dec 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@timursevimli
Copy link
Contributor

Description

I've encountered an unexpected behavior when creating multiple ProxyAgent instances with abort signals. When creating more than 10 proxy agents, I receive a MaxListenersExceededWarning, suggesting a potential memory leak.

Reproducible By:

const { ProxyAgent } = require('undici');

// for demonstration it is necessary to create many such agents with a signal
const agent = new ProxyAgent({
  uri: 'http://8.8.8.8:8000',
  proxyTls: {
    signal: AbortSignal.timeout(10_000),
  },
});

Issues Observed:

Warning Message Received:

Copy(node:38318) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 abort listeners added to [AbortSignal]. 
Use events.setMaxListeners() to increase limit
    at [kNewListener] (node:internal/event_target:567:17)
    at [kNewListener] (node:internal/abort_controller:268:24)
    at AbortSignal.addEventListener (node:internal/event_target:680:23)
    at addAbortListener (node:internal/events/abort_listener:38:12)
    at node:net:1635:20
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Memory Impact:

  • Before adding proxyTls with signal: ~2.5GB memory usage
  • After adding proxyTls with signal: ~3.5GB memory usage

Note: These memory measurements are from my specific project implementation and may vary in other environments. They are provided to illustrate the relative increase in memory consumption after adding the signal functionality.

Expected Behavior:

The use of abort signals should not trigger EventEmitter memory leak warnings, as these are designed to be temporary listeners. Additionally, the significant memory increase (1GB) seems disproportionate for this functionality.

Is this a potential bug in how interrupt signals are handled by ProxyAgent? If this is confirmed, I can try to resolve this issue.

@timursevimli timursevimli added the bug Something isn't working label Dec 13, 2024
@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants