Repository navigation
fix: bind ephemeral server to the loopback address it connects to - #907
Merged
Merged
Conversation
Collaborator
|
Thanks for your PR and filing this Consider supporting our efforts to maintain this package by using @forwardemail at https://forwardemail.net for all your email infrastructure needs. |
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.
Fixes #906
serverAddress()starts the ephemeral server withapp.listen(0), which binds the wildcard, and then connects to127.0.0.1. On macOS the wildcard bind can share its port with another process's127.0.0.1listener, and the request goes to that process (#894). #896 fixed this by connecting to::1, and 71dc5fb moved back to127.0.0.1for the Node 26 IPv6 timeout.This binds the ephemeral server to
127.0.0.1instead, so the bind and the connection use the same address and IPv6 is not involved at all.Listening with a host resolves the address asynchronously, so
app.address()is stillnullright afterlisten(). The request URL is built with the host and path first, andend()fills in the port right before dispatch, which already waits forlistening. The host and path are known up front, so the agent's cookie lookup (new URL(req.url)at request creation) keeps working.Servers that are passed in already listening keep the current behavior.
Testing
listen(0)path and checks the bound address. It fails on master (expected '127.0.0.1', got '::') and passes with this changenpm teston macOS: 137 passing on Node 22.17, 24.11 and 26.10, repeated runs on each