Recently, I want to make a function on the server side. Long polling is used. Whether it is eggjs or expressjs, some unhandled exceptions will be constantly thrown during the development process.
errno: "ECONNRESET"
code: "ECONNRESET"
syscall: "read"
Finally, it was found that the original long connection did not listen to the close event. The process is roughly like this:
1. The user establishes the request pending state
2. The server emit event is used to perform a specific task
3. The execution is completed or the time is up, response returns information
If the user closes the http request between 2 and 3, then the response will throw an exception at this time;
ctx.req.on('close', function(){
iscancel = true;
console.log('cancel');
})
if(iscancel){
return;
}
Record~~~~~~~~~~~~