grpc-swift
grpc-swift copied to clipboard
Server connection still open after Server.close() ?
What are you trying to achieve?
I am not sure if this might be a bug or if I am just using the APIs incorrectly, so I am creating this issue as a question and hope that somebody can help me.
We are starting a GRPC server on iOS:
let server = Server.insecure(group: self.serverGroup).withServiceProviders(serviceProviders).bind(host: "0.0.0.0", port: 0)
We are using the Health Check Service (the streaming API is not used) to check from another client, if the services are reachable.
We have a use case where we manually want to shutdown der server on iOS and expect that the connection is closed so that a call to the Health Check Service results in an error.
What have you tried so far?
To manually close the server we used this method: Server.close(). This method returns successful but a call from a client to any service on the server still comes through, the service instance is still there and happily responds to requests. This is different to for example when the app is closed. Then any call instantly receives an error response.
Additional Information
- using SwiftNIO
- Client is written in Rust
- using Grpc-swift 1.6.0
close() should really be "stop accepting connections" which isn't terribly helpful API.
initiateGracefulShutdown() is probably closer to what you want, it stops accepting new connections and waits for open connections to close (by allowing open RPCs to complete).
There is nothing in-between to say "stop accepting new connection and close the existing ones right now". initiateGracefulShutdown should probably accept a deadline after which any remaining open RPCs are cancelled and any connections are closed.
Well, this is the documentation from the close() method:
Shutdown the server immediately. Active RPCs and connections will be terminated.
It's a pitty that it doesn't work like that, because that's exactly what I needed.
Thank you for mentioning initiateGracefulShutdown(). I think that works for us, we just need to stop streaming RPCs manually.
Edit
Relevant code section. To be this sounds like something is not working correctly with the close() method. Maybe even with channel.close() which is called here.