Skip to content

Conversation

@Ayush-Bansal08
Copy link

fix: Gracefully exit process on EADDRINUSE in test servers

The test helper servers (bucket-server, receipts-server, etc.)
were crashing due to an unhandled 'error' event when attempting to
bind to a port that was already in use (EADDRINUSE).

This commit adds an explicit error handler to the server instance
to catch EADDRINUSE, log a warning, and exit the test process
with an error code (1) instead of allowing the application to
throw an unhandled exception.

Before it was showing:
Error: listen EADDRINUSE: address already in use :::[PORT]
at Server.setupListenHandle [as _listen2] (net.js:1317:21)
at listenInCluster (net.js:1382:12)
at Server.listen (net.js:1465:7)
at Object. ([file-path]/bucket-server.js:[LINE]:[COL])
// ... followed by a full stack trace and process exit

After it was showing:
Error: Port [PORT] is already in use. Test server failed to start.

Process exits with code 1 instead of crashing, allowing clean CI failure.

Fixes #554

@Ayush-Bansal08
Copy link
Author

Hi maintainers 👋
This PR fixes graceful process exit on EADDRINUSE in test servers.
Please let me know if any changes or improvements are needed. Happy to update!

@Ayush-Bansal08
Copy link
Author

@travis can you please review it?

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.

Add error handling to test mock HTTP servers to prevent uncaught exceptions

2 participants