Skip to content

fix: match ephemeral server address family - #896

Merged
titanism merged 1 commit into
forwardemail:masterfrom
pnookala-godaddy:codex/ephemeral-loopback-bind
Sep 22, 2026
Merged

titanism merged 1 commit into
forwardemail:masterfrom
pnookala-godaddy:codex/ephemeral-loopback-bind

Conversation

@pnookala-godaddy

Copy link
Copy Markdown
Contributor

Summary

  • build Supertest request URLs from the test server's bound address family
  • translate wildcard listeners to the matching loopback address
  • add a deterministic dual-stack regression that proves requests cannot be routed to a foreign IPv4 listener

Background

serverAddress() currently starts an ephemeral server with listen(0) but always connects to 127.0.0.1. On macOS, Node commonly binds that server to the IPv6 wildcard. A separate process can own the same port specifically on IPv4, causing Supertest's request to reach the foreign process.

This keeps the existing synchronous ephemeral bind and uses only public Node APIs. IPv6 addresses are bracketed for URL construction, and wildcard addresses are converted to their same-family loopback equivalents.

Fixes #894

Testing

  • npm test on Node 24: 131 passing, including lint and coverage
  • full 131-test suite: 20 consecutive passing runs on Node 24
  • full 131-test suite: passing on Node 22
  • regression verified to fail before the source change by receiving foreign-server instead of supertest-server

@pnookala-godaddy

pnookala-godaddy commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@titanism checking to see if we could merge the pr

@titanism
titanism merged commit 7fb34e7 into forwardemail:master Sep 22, 2026
@titanism

titanism commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

version v7.3.0 now available via npm, see https://github.com/forwardemail/supertest/releases/tag/v7.3.0 and 71dc5fb

please consider supporting our open source maintenance efforts by using our 100% open source email service at https://forwardemail.net 馃檹

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.

[fix] Supertest attempts to bind a port that is already in use on a Mac, causing random failures

2 participants