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 due to Sentry.init calls on window refresh #847

Closed
3 tasks done
Rafatcb opened this issue Mar 15, 2024 · 2 comments · Fixed by #849
Closed
3 tasks done

MaxListenersExceededWarning due to Sentry.init calls on window refresh #847

Rafatcb opened this issue Mar 15, 2024 · 2 comments · Fixed by #849

Comments

@Rafatcb
Copy link

Rafatcb commented Mar 15, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Electron SDK Version

4.20.0

Electron Version

22.3.27

What platform are you using?

Windows

Link to Sentry event

No response

Steps to Reproduce

  1. Add a call to Sentry.init on renderer. (I'm using React, so this is called outside the App component)
  2. Refresh the page a few times (probably 10~15 times).

Expected Result

No warning.

Actual Result

Warning:

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

If you add process.on('warning', e => console.warn(e.stack)) on your main process you can see the stack trace:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 destroyed 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 IpcMainImpl.<anonymous> (D:\repo\node_modules\@sentry\electron\src\src\main\ipc.ts:268:14)
    at IpcMainImpl.emit (node:events:513:28)
    at IpcMainImpl.emit (node:domain:489:12)
    at EventEmitter.<anonymous> (node:electron/js2c/browser_init:2:81099)
    at EventEmitter.emit (node:events:513:28)
    at EventEmitter.emit (node:domain:489:12)

Which points to this part of Sentry's code:

ipcMain.on(IPCChannel.RENDERER_START, ({ sender }) => {
const id = sender.id;
// In older Electron, sender can be destroyed before this callback is called
if (!sender.isDestroyed()) {
// Keep track of renderers that are using IPC
KNOWN_RENDERERS = KNOWN_RENDERERS || new Set();
KNOWN_RENDERERS.add(id);
sender.once('destroyed', () => {
KNOWN_RENDERERS?.delete(id);
});
}
});

I think it could be updated to:

if (!sender.isDestroyed()) { 
 // Keep track of renderers that are using IPC 
 KNOWN_RENDERERS = KNOWN_RENDERERS || new Set(); 

+ if (KNOWN_RENDERERS.has(id)) {
+   return;
+ }

 KNOWN_RENDERERS.add(id); 

 sender.once('destroyed', () => { 
   KNOWN_RENDERERS?.delete(id); 
 }); 
} 
@timfish
Copy link
Collaborator

timfish commented Mar 16, 2024

Hi @Rafatcb, thanks for reporting this!

@Rafatcb
Copy link
Author

Rafatcb commented Mar 18, 2024

@timfish thanks for the fix 😃

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

Successfully merging a pull request may close this issue.

2 participants