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
Problem description:
When an HTTP server decides to send a response while the request body is still being sent, there are cases (race condition) where the client receives an ECONNRESET error without receiving the response.
Example:
consthttp=require("http");constnet=require("net");conststream=require("stream");constPORT=1235;letserverReceivedRequestHeaders=false;// create HTTP serverconstserver=http.createServer((request,response)=>{serverReceivedRequestHeaders=true;response.writeHead(401,"test error");response.end();});server.listen(PORT,(error)=>{if(error){console.log(error);return;}// send requestconstrequest=http.request({hostname: 'localhost',method: 'POST',path: '/',port: PORT});request.once("response",(response)=>{console.log("response",response.statusCode);});request.once("error",(error)=>{console.log("request error",error);});// keep sending more request body until the server receives the request headersconstrequestBody=newstream.PassThrough();constwriteMore=(cb)=>{requestBody.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",(error)=>{if(error){cb(error);}elseif(serverReceivedRequestHeaders){cb();}else{writeMore(cb);}});}requestBody.pipe(request);writeMore(()=>undefined);});
@bnoordhuis that looks similar indeed. And in my case it's quite serious since I have to talk to a server that has this behavior and it's not under my control. And I do need that response.
Okay, I'll close this out as a duplicate. You should chime in on the other issue but as you can probably tell from the discussion, it's not clear what the solution should be.
Problem description:
When an HTTP server decides to send a response while the request body is still being sent, there are cases (race condition) where the client receives an ECONNRESET error without receiving the response.
Example:
Expected output:
Actual output:
Notes:
The text was updated successfully, but these errors were encountered: