-1

What the title says. I ran into a bug where the issue was an express endpoint not ending the request connection which caused it to seemingly hang. I am still confused how the request and response flow looks like.

ashkan117
  • 868
  • 10
  • 16

1 Answers1

1

The Express http server object has a configurable timeout and after that timeout with no response on the http connection, the server will close the socket.

Similarly, most http clients at the other end (such as browsers) have some sort of timeout that will likely close the TCP socket if they've been waiting for a response for too long.

The http server timeout is built into the underlying http server object that Express uses and you can see how to configure its timeout here: Express.js Response Timeout. By default, the nodejs http server timeout is set to 0 which means "no timeout" is enforced.

So, if you have no server timeout and no client timeout, then the connection will just sit there indefinitely.

You can configure your own Express timeout with:

// set server timeout to 2 minutes
server.timeout = 1000 * 60 * 2;

See doc here.

Where server is the http server object created by either http.createServer() or app.listen().

jfriend00
  • 683,504
  • 96
  • 985
  • 979