grpc-dart
grpc-dart copied to clipboard
"Cannot add event after closing" server error when client abruptly goes away
Run server from hello world example. Run client and kill it. Repeat many time Time to time, killing the client cause server crash. See trace bellow.
Also the client is very slow (4 request per sec). Don't know if related or not.
GRPC Version : from the repository (../..) (0.4.0 ?)
Repro steps
See above.
Details
Server Stack Trace:
Unhandled exception:
Bad state: Cannot add event after closing
#0 _StreamController.add (dart:async/stream_controller.dart:584)
#1 _StreamSinkWrapper.add (dart:async/stream_controller.dart:858)
#2 TransportStream.sendHeaders (package:http2/transport.dart:241:10)
#3 ServerHandler.sendTrailers (package:grpc/src/server/handler.dart:310:13)
#4 ServerHandler._sendError (package:grpc/src/server/handler.dart:359:5)
#5 ServerHandler._onResponse (package:grpc/src/server/handler.dart:248:7)
#6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316)
My Quick and dirty workaround : handler.dart: 248 try { _sendError(grpcError); } catch(err) { print(err); }
cc @jakobr-google
If you sleep 10 seconds in sayHello function, run client and exit in 10 seconds, it will always crash in the demo. for example:
class GreeterService extends GreeterServiceBase {
@override
Future<HelloReply> sayHello(ServiceCall call, HelloRequest request) async {
await new Future.delayed(new Duration(seconds: 10));
return new HelloReply()..message = 'Hello, ${request.name}!';
}
}
stack:
Unhandled exception:
NoSuchMethodError: The method 'remove' was called on null.
Receiver: null
Tried calling: remove(":status")
#0 Object.noSuchMethod (dart:core-patch/dart:core/object_patch.dart:46)
#1 ServerHandler.sendTrailers (package:grpc/src/server/handler.dart:295:23)
#2 ServerHandler._sendError (package:grpc/src/server/handler.dart:359:5)
#3 ServerHandler._onResponse (package:grpc/src/server/handler.dart:248:7)
#4 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316)
#5 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330)
#6 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:257)
#7 _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:763)
#8 _StreamController._add (dart:async/stream_controller.dart:639)
#9 new Stream.fromFuture.<anonymous closure> (dart:async/stream.dart:107)
#10 _RootZone.runUnary (dart:async/zone.dart:1381)
#11 _FutureListener.handleValue (dart:async/future_impl.dart:129)
#12 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633)
#13 _Future._propagateToListeners (dart:async/future_impl.dart:662)
#14 _Future._complete (dart:async/future_impl.dart:467)
#15 _SyncCompleter.complete (dart:async/future_impl.dart:51)
#16 _completeOnAsyncReturn (dart:async-patch/dart:async/async_patch.dart:292)
#17 GreeterService.sayHello (file:///Users/chenxinxin/code/grpc-dart/example/helloworld/bin/server.dart:28:5)
#18 _RootZone.runUnary (dart:async/zone.dart:1381)
#19 _FutureListener.handleValue (dart:async/future_impl.dart:129)
#20 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633)
#21 _Future._propagateToListeners (dart:async/future_impl.dart:662)
#22 _Future._complete (dart:async/future_impl.dart:467)
#23 new Future.delayed.<anonymous closure> (dart:async/future.dart:310)
#24 Timer._createTimer.<anonymous closure> (dart:async-patch/dart:async/timer_patch.dart:21)
#25 _Timer._runTimers (dart:isolate-patch/dart:isolate/timer_impl.dart:382)
#26 _Timer._handleMessage (dart:isolate-patch/dart:isolate/timer_impl.dart:416)
#27 _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)
cc @sigurdm
Will it be fixed? I'm connecting to server -> send message to StreamController -> reload app -> subscribe on stream and send message again -> it leads to server crash. Bad state: Cannot add event after closing