fix: detect port-in-use before starting (#1234)#1316
Open
echopi wants to merge 2 commits intoavwo:masterfrom
Open
fix: detect port-in-use before starting (#1234)#1316echopi wants to merge 2 commits intoavwo:masterfrom
echopi wants to merge 2 commits intoavwo:masterfrom
Conversation
99ebb0d to
f751582
Compare
3 tasks
ce931ce to
9b19ecf
Compare
Node.js v17+ (OpenSSL 3.0) rejects EE certificates with keys smaller than 2048-bit. The test certs were 1024-bit, causing ERR_SSL_EE_KEY_TOO_SMALL. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port 8081 is commonly used by other services (e.g. AliLang), causing EADDRINUSE when running tests. Use a high port to reduce conflicts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9b19ecf to
1963b6a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
server.on('error')handler inlib/index.jsto catchEADDRINUSEand print a friendly error messageexclusive: trueinserver.listen()to ensure port conflicts are detected across platforms (macOS usesSO_REUSEADDRby default)Fixes #1234
What changed
lib/index.js (+10/-1):
EADDRINUSE:server.listen()changed to use{ exclusive: true }to preventSO_REUSEADDRfrom masking port conflictstest/units/port-in-use.test.js + test/helpers/start-whistle.js: Standalone test that occupies a port, starts whistle on the same port, and verifies the friendly error message appears.
Design decisions
lib/index.jsserver error event, notindex.jspre-check — avoids TOCTOU race, preserves sync return valueexclusive: trueSO_REUSEADDRallows duplicate binds silentlyuncaughtExceptionhandler in same file do process cleanupTest plan
# Standalone port-in-use test node test/units/port-in-use.test.jsexclusive: true🤖 Generated with Claude Code