In the batteries-included `apollo-server`, ApolloServer.stop() can hang indefinitely waiting for connections to close (just like net.Server.close)
See original GitHub issueDescription
I’ve been trying to reproduce an issue where the server process appears to be orphaned and continues running despite being killed.
I’m using tsc-watch
to watch for code changes and when a file change is detected it sends SIGTERM
to the process and then recreates it by invoking node ./build
again.
However in this scenario some simple code in my application is unexpectedly causing the process to be orphaned and never exit as multiple processes are created all vying for the same port.
Version Info
apollo-server: 2.13.0
Expected Behavior
The server stops when await server.stop()
is called
Actual Behavior
The server does not stop and the call to server never finishes, the process never exits.
Reproduction
https://github.com/justinmchase/apollo-lerna-repro
Steps
npm i
npm start
# open http://localhost:3000 in browser
This will cause a simple react page to continually call the api. If you open this file: https://github.com/justinmchase/apollo-lerna-repro/blob/master/packages/api/src/index.ts
And simply save it you will see the server restart seamlessly.
Now go and uncomment this line: https://github.com/justinmchase/apollo-lerna-repro/blob/master/packages/api/src/index.ts#L61
And observe that the call to await server.stop()
does not stop the server and never returns and the process is never exited.
- Related to https://github.com/lerna/lerna/issues/2284
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:23 (7 by maintainers)
Top GitHub Comments
After testing this extensively I think that all the complexity of this sample can be ignored and simply starting the server and calling
await server.stop()
is the only problem. The server does not alway stop and the time it can take to stop is highly variable and it can actually continue to accept and process new incoming connections while hung in the stop method.If I simply close the process then the server does stop (of course) but it will abruptly end all ongoing requests mid stream.
What I expect to happen is for the server to immediately stop accepting incoming connections and once all ongoing connections are completed then the call to stop resolves. If there are no currently processing requests then it would end immediately.
Check out #4908.