Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#906·supertest

macOS: requests can still reach another local process after #896 (regressed in 71dc5fbe)

Author: JH8459Created Sep 29, 2026Updated Sep 29, 2026

Hi, thanks for maintaining supertest. We use it heavily and it has been great.

I think the problem from #894 came back in 7.3.0. #896 fixed it by connecting to ::1 when the ephemeral server binds ::. Then 71dc5fbe (same day) switched that mapping back to 127.0.0.1 to avoid the Node 26 IPv6 loopback timeout, which makes sense, but the server is still bound with app.listen(0). So the bind is the wildcard and the connection is IPv4 loopback again.

On macOS a wildcard bind succeeds even when another process holds 127.0.0.1 on the same port, and the connection goes to that process. Small repro with plain http (Node 24.11, macOS 26):

javascript
const http = require('http');

const other = http.createServer((req, res) => res.end('other process'));
other.listen(0, '127.0.0.1', () => {
  const port = other.address().port;
  const app = http.createServer((req, res) => res.end('app'));
  // what listen(0) does, just pinned to a port that is already taken on 127.0.0.1
  app.listen(port, () => {
    console.log(app.address()); // { address: '::', family: 'IPv6', port }
    http.get(`http://127.0.0.1:${port}/`, (res) => {
      res.on('data', (d) => console.log('127.0.0.1 ->', String(d))); // other process
    });
    http.get(`http://[::1]:${port}/`, (res) => {
      res.on('data', (d) => console.log('::1 ->', String(d))); // app
    });
  });
});

The ephemeral allocator doesn't skip ports that are only held on 127.0.0.1. When I kept 3000 such listeners open and called listen(0) 20000 times, every one of those 3000 ports got handed out at some point. With listen(0, '127.0.0.1') none of them did. In our suite it shows up as a rare 401/404 from some unrelated local app (an IDE, a desktop app) instead of our server.

The regression test from #896 passes an already listening ::1 server, so it doesn't go through the listen(0) path. That's probably why this wasn't caught.

I think binding the ephemeral server to 127.0.0.1 would cover both cases, since it matches the address we connect to and never touches IPv6. The catch is that listening with a host resolves the address asynchronously, but 7.3.0 already waits for listening before dispatch, so the port can be filled in there. I'll open a PR with that change and a regression test right after this. Happy to adjust if you'd prefer a different approach.

Source: forwardemail/supertest

View original on GitHubView discussion on GitHub