MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
MIT License
499 stars 14 forks source link

Jest tests exit with "A worker process has failed to exit gracefully and has been force exited." #19

Closed MatthewWid closed 2 years ago

MatthewWid commented 3 years ago

The Jest test suite has an issue that Jest reports as a memory leak whereby some handles are not being properly destroyed after the tests finish.

The complete error message is:

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.

Running with --detectOpenHandles simply causes the test run to hang and gives no additional information, perhaps related to this issue in Jest itself.

Sometimes, nondeterministically, Jest will also report the following:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue.

Perhaps related to this Jest issue.


To reproduce:

  1. Follow the 'Local Development' steps in the README.

My assumption here is that in one of the tests that imperatively destroys the connection between the server and the EventSource is not cleaning up the EventSource reconnect, and it is attempting to connect again instead of being closed causing a leak. But I am not totally sure.

MatthewWid commented 2 years ago

Closing as this appears to be fixed in v0.7.0 after updating all dependencies to their latest versions. Not sure exactly which dependency was causing the issue, but I suspect it was an update to a Jest-Typescript package.