Open North101 opened 4 years ago
This is still a bug. shutdown()
does not force streams to close and waits for them to finish. The only workaround is to ensure the streams are closed before calling shutdown()
. However I find that call.sendTrailers()
must be manually called at the end of the stream generator because it is not automatically called at the end of the stream unlike how it is documented.
The workaround I have at the moment looks like this in the service RPC implementation:
// sendTrailers is not always called automatically when the stream ends
// despite the documentation.
// Without calling this, the grpc stream will hang and never close.
final controller = StreamController<Event>(
onCancel: () => call.sendTrailers(),
);
// When upstream stream is done, cancel this one
controller.addStream(stream).then((_) => controller.close());
return controller.stream;
When the server is streaming data to a client and server.shutdown() is called, it'll hang as the connection never finishes.
Repro steps
replace the helloworld.proto, server.dart and client.dart files with the ones bellow and re-run
run
dart bin/sever.dart
and then quickly rundart bin/client.dart
(as the server will attempt to close after 5 seconds).The server never fully shuts down as the connection.finish() call never finishes and both the server and client will hang until the server process is closed.
If you change https://github.com/grpc/grpc-dart/blob/master/lib/src/server/server.dart#L147 to
then it works as I'd expect, though this is probably not the proper fix for this.
Details
helloworld.proto
server.dart
client.dart