awakesecurity / gRPC-haskell

Haskell gRPC support
https://hackage.haskell.org/package/grpc-haskell
Apache License 2.0
238 stars 75 forks source link

Server: Make graceful termination timeout customizable #147

Open unclechu opened 1 year ago

unclechu commented 1 year ago

Depending on particular user cases of gRPC server there might be (and there are in fact) cases where hard-coded 30 seconds is not enough to gracefully terminate currently open connections. This value better be customizable and left up to the library users to decide how long it should wait before forcible closing the connections.

In Network.GRPC.LowLevel.Server module (core/src/Network/GRPC/LowLevel/Server.hs file) in stopServer function there is this line:

shutdownEvent <- pluck scq shutdownTag (Just 30)

Here 30 seconds timeout is hard-coded. I guess Server data-type of this module can be extended to hold time graceful termination timeout value to use for that pluck function.

This value can be added to Network.GRPC.HighLevel.Generated.ServiceOptions data type and this 30 seconds can be set as default for Network.GRPC.HighLevel.Generated.defaultServiceOptions so there a user would customize the value. And then at some point it would be passed to the Server (probably to ServerConfig first?).

ixmatus commented 1 year ago

@unclechu this sounds like a useful change! Thanks for documenting it :)

We're very busy within Arista at the moment so we're unlikely to get to this unless this became a blocker for someone. We're very open to contributions though, so if you implement this for yourself, please consider making it a pull request!