Open hildoer opened 6 years ago
Upon further inspection it looks like the problem is that for https server instances, it fires both 'connection' and 'secureConnection' events. Then, when you call server.stop(), the 'connection' socket is idle even though the 'secureConnection' socket has a single request on it. The loop calling endIfIdle then kills the 'connection' socket, which actually kills the 'secureConnection' socket also.
My guess is that we need to listen to only one of the two events depending on whether its a secure server or not.
Final update... After some digging it looks like 'secureConnection' is fired off by TLS server, not HTTPS. Whereas 'connection' is fired by HTTP server. According to all docs for latest versions of node 4, 6, 8 and 10, a TLS server object will have a function named getTicketKeys. If we test for presence of this function on the server object passed into stoppable, and only do one of the event listens onConnection, this solves the problem.
Let me know if this sounds like a suitable hook in the system. It feels a little hacky but the API for the TLS server object is way stable. I think we can depend on it. If all sounds good I will get a pull request together.
I am seeing an issue where stoppable is killing in-flight HTTPS connections. My test verification sets up an HTTPS server, applies stoppable, makes a request (the handler will delay 1 second to reply), calls server.stop() immediately without waiting for the request to return, and the request then errors out immediately with "socket hang up" error.
However, if I use HTTP instead, and leave all other code the same, everything works correctly and the server.stop() command waits the 1 seconds for the delay handler to return, sees the connection ended, then the stop() callback fires.
I have also tested with keep alive enabled and disabled on the request side of things. In both cases HTTP works, and HTTPS gets a socket hang up.
Here is my test file. To run it, install async, request and stoppable, set the "configure test here" values, and then run the file with node v6 or v8. For config, the problems occur for secure = true, no matter what the other two config values are.
Keep in mind, if you use the config values of applyStoppable = false and keepAlive = true, the server will hang forever. In that case ctrl+c to exit.