supertest icon indicating copy to clipboard operation
supertest copied to clipboard

Discourage implicit use of ephemeral ports in supertest.serverAddress

Open kwasimensah opened this issue 4 years ago • 1 comments

I've been search for flakes in my test for weeks and I think the solution is around supertest's usage of ephemeral ports (binding to port 0).

Full writeup at at https://stackoverflow.com/questions/63343123/nodesupertest-flakes-with-client-network-socket-disconnected-before-secure-tls/63343124#63343124.

tldr; supertest.serverAddress will call app.listen(0) if the server isn't running yet. But the socket will have the SO_REUSEADDR flag set which means it can conflict with any other process that's also using SO_REUSEADDR on a port in the ephemeral range. This causes the client to spuriously fail at making a connection.

kwasimensah avatar Aug 10 '20 19:08 kwasimensah

I have debugged whole day to find macbook related ephemeral ports, i believe we should be given option to pick a port and more granular options. macbook has AV, firewall and other stuff running, returning 403 on some of them and supertest replies that express did this.

7c avatar Jan 27 '24 14:01 7c