question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In the batteries-included `apollo-server`, ApolloServer.stop() can hang indefinitely waiting for connections to close (just like net.Server.close)

See original GitHub issue

Description

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:15
  • Comments:23 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
justinmchasecommented, Jul 8, 2020

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.

1reaction
glassercommented, Feb 8, 2021

Check out #4908.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Reference: ApolloServer - Apollo GraphQL Docs
This article documents the ApolloServer class from the @apollo/server package. You can use the ApolloServer class to create an instance of Apollo Server...
Read more >
In the batteries-included `apollo-server`, ApolloServer.stop() can ...
In the batteries-included `apollo-server`, ApolloServer.stop() can hang indefinitely waiting for connections to close (just like net.Server.close)
Read more >
apollo-server-core | Yarn - Package Manager
This package implements the core logic of Apollo Server. It exports a base version of ApolloServer . Typically you do not use this...
Read more >
How do I debug error ECONNRESET in Node.js?
You might have guessed it already: it's a connection error. "ECONNRESET" means the other side of the TCP conversation abruptly closed its end...
Read more >
How to fix common macOS Ventura issues - Setapp
Inevitably, users encounter some Ventura issues, including Ventura installation failed, Ventura won't boot, and more. But don't quit just yet!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found