trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.62k stars 675 forks source link

Track all HTTP connects and force them closed on server shutdown #2788

Open davidmurdoch opened 2 years ago

davidmurdoch commented 2 years ago

For clients that connect to the ganache server over HTTP with keepAlive ganache will not immediately close those connections when the server is shutdown, these connections wait until the keepAlive timeout is finished (10 seconds) or until the client sends another request.

See https://github.com/uNetworking/uWebSockets.js/issues/663 and https://github.com/trufflesuite/ganache/pull/2667

This isn't just a uWS issue, node core also requires this pattern: https://github.com/nodejs/node/issues/2642

MicaiahReid commented 2 years ago

@davidmurdoch, can you clarify on the below?

these connections wait until the keepAlive timeout is finished (10 seconds) or until the client sends another request.

Are you saying that if the client sends another request, the keepAlive timeout will start over, and this will hole open the connection? @cds-amal and I are looking into another issue with Ganache not shutting down and are wondering if this is the cause.

davidmurdoch commented 2 years ago

As of #2667 Ganache will close the connection if another request is sent within the keepAlive window. What I'm am saying above is that we don't proactively close the keep alive connection (we wait for it to timeout or for another request to come in over the connection in order to close it).

LuKks commented 1 year ago

In case it's useful: https://github.com/LuKks/graceful-http