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

fix: remove process listeners after stopping the server #4013

Merged
merged 3 commits into from Nov 12, 2021

Conversation

snitin315
Copy link
Member

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

No

Motivation / Use-Case

fix memory leak warnings in e2e tests.

Screenshot 2021-11-07 at 5 41 57 PM

Breaking Changes

None

Additional Info

No

@codecov
Copy link

codecov bot commented Nov 8, 2021

Codecov Report

Merging #4013 (3896404) into master (270da15) will increase coverage by 0.12%.
The diff coverage is 95.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4013      +/-   ##
==========================================
+ Coverage   92.62%   92.74%   +0.12%     
==========================================
  Files          14       14              
  Lines        1410     1420      +10     
  Branches      519      524       +5     
==========================================
+ Hits         1306     1317      +11     
+ Misses         96       95       -1     
  Partials        8        8              
Impacted Files Coverage Δ
lib/Server.js 94.16% <95.83%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 270da15...3896404. Read the comment docs.

setupTest.js Outdated Show resolved Hide resolved
@snitin315 snitin315 force-pushed the chore/fix-memory-leak-warnings branch from a186750 to 447fe4d Compare November 8, 2021 10:42
@snitin315 snitin315 changed the title chore: fix memory leak warnings fix: remove process listeners after stopping the server Nov 8, 2021
lib/Server.js Outdated
// We add listeners to signals when creating a new Server instance
// So ensure they are removed to prevent EventEmitter memory leak warnings
process.removeAllListeners("SIGINT");
process.removeAllListeners("SIGTERM");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not remove all of them just only our, move our close function above the file and use removeListener

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above where?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere here https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L17, like

if (needForceShutdown) {
            exitProcess();
          }

          this.logger.info(
            "Gracefully shutting down. To force exit, press ^C again. Please wait..."
          );

          needForceShutdown = true;

          this.stopCallback(() => {
            if (typeof this.compiler.close === "function") {
              this.compiler.close(exitProcess);
            } else {
              exitProcess();
            }
});

from https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L1177

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. just move it in function above the Server class and remove this listener in close

@alexander-akait alexander-akait merged commit d198e4e into master Nov 12, 2021
@alexander-akait alexander-akait deleted the chore/fix-memory-leak-warnings branch November 12, 2021 17:44
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

Successfully merging this pull request may close these issues.

None yet

2 participants