You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
7.3.1: streaming requests (.write) against an app factory hit port 80 (ECONNREFUSED) #911
supertest 7.3.1 regresses streaming requests created with .write() when built from an app factory (request(app)), where supertest starts its own ephemeral server. The underlying request is created against http://127.0.0.1/path (default port 80) instead of the actual ephemeral port, producing ECONNREFUSED. 7.3.0 works.
Environment
supertest: 7.3.1 (7.3.0 works)
superagent: 10.3.0
Node: 26.10.0 (macOS/darwin)
Root cause
After #907 (v7.3.1), serverAddress() returns a portless placeholder URL when app.address() is null (the loopback bind is resolved asynchronously) and defers the real URL to end() / dispatch():
// lib/test.js (7.3.1)if(!addr){this._serverPath=path;constprotocol=appinstanceofServer ? 'https' : 'http';returnprotocol+'://127.0.0.1'+path;// no port yet}// ...dispatch=()=>{removeStartListeners();try{if(this._serverPath!==undefined){this.url=this.formatServerUrl(server,server.address(),this._serverPath);this._serverPath=undefined;}super.end(finish);} ...
However, superagent's streaming API builds the request object eagerly, before end() runs:
Non-streaming styles are unaffected: .send(Buffer), .field()/.attach() and plain .get()/.post() work.
Suggested fix
Make the real URL available before a caller can create the request, or make write()/pipe() wait for listening (as end() already does), so the deferred-URL mechanism is not observable to superagent's eager request creation.
Impact
Blocks upgrading to 7.3.1 for anyone using the raw streaming API (.write()/.pipe()); only a test rewrite to .send(Buffer) or .field()/.attach() is available as a workaround.
Activity