question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate log output and MaxListenersExceededWarning warning (regression in 0.47.1)

See original GitHub issue

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Browsers

Chromium (Chrome, Brave, etc.), Firefox

Reproduction repository

https://github.com/kleinfreund/kuma-gui/tree/feat/rework-dataplanes-view

Reproduction steps

  1. In package.json, change the msw dependency from 0.47.0 to ^0.47.3
  2. Run yarn install
  3. Run yarn run dev
  4. Browse around the UI and observe the console log entries

Current behavior

Many redundant log entries appear for requests that are only made once (and handled once). Example:

RestHandler.ts:183 [MSW] 09:08:29 GET http://localhost:5681/ (200 OK)

The following warning appears:

events.js:46 MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 response:mocked listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (http://localhost:8080/node_modules/.vite/deps/msw.js?v=9b1b86e7:597:19)
    at StrictEventEmitter2.addListener (http://localhost:8080/node_modules/.vite/deps/msw.js?v=9b1b86e7:608:14)
    at StrictEventEmitter2.once (http://localhost:8080/node_modules/.vite/deps/msw.js?v=9b1b86e7:868:36)
    at Object.onMockedResponse (http://localhost:8080/node_modules/.vite/deps/msw.js?v=9b1b86e7:22101:34)
ProcessEmitWarning		@	events.js:46
_addListener			@	events.js:219
addListener			@	events.js:227
StrictEventEmitter2.once	@	StrictEventEmitter.js:34
onMockedResponse		@	createRequestListener.ts:76
await in onMockedResponse (async)		
handleRequest			@	handleRequest.ts:127
await in handleRequest (async)		
(anonymous)			@	createRequestListener.ts:34
(anonymous)			@	setupWorker.ts:93

Expected behavior

The logs aren’t unnecessarily redundant and there is no max listeners exceeding warning.

Notes

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:10
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
kettanaitocommented, Sep 27, 2022

@snaka, that must have been the root cause. We’ve just merged and released the fix to strict-event-emitter. Would anyone be interested in bumping that dependency in MSW in a pull request?

On a related note, I’ve noticed that https://github.com/open-draft/strict-event-emitter is heavily under-tested. If you’d like to contribute to a package we use extensively in MSW and beyond, writing tests for strict-event-emitter is a fantastic place to start!

2reactions
kleinfreundcommented, Sep 27, 2022

@snaka That looks promising considering that https://github.com/mswjs/msw/pull/1392 introduced calls to context.emitter.once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fix: remove duplicate response logging in the browser console ...
Update strict-event-emitter version that to resolve log duplicates. Fixes Duplicate log output and MaxListenersExceededWarning warning (regression in 0.47.1) # ...
Read more >
Possible EventEmitter memory leak detected. 11 message lis ...
I've received this warning many times, but usually only for two ... if ( 'MaxListenersExceededWarning' == err.name ) { console.log('o ...
Read more >
rollup changelog
Fix a situation where invalid code was rendered when dynamically importing a module with synthetic named exports when preserving modules (#3738) ...
Read more >
Actions execution throws "MaxListenersExceededWarning"
After enabling multiple Actions of the same trigger, I started getting warnings on the Realtime Webtask Log extension, specifically:.
Read more >
griebnitz/node_modules/rollup/CHANGELOG.md - GitLab
Fix a severe performance regression when the same module is imported by a lot of ... #3575: Handle some cases of duplicate export...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found