grpc-dart icon indicating copy to clipboard operation
grpc-dart copied to clipboard

Sending data after the client got closed crashed the program instead of sending an error.

Open guyluz11 opened this issue 3 years ago • 0 comments

Sending data after the client got closed crashed the program instead of sending an error upwards for the programmer to handle it.

<version of the grpc-dart packages used; see your pubspec.lock file> grpc: ^3.0.2

Repro steps

  1. step1
  2. step2
  3. step3

Expected result: The error gets passed up and can be captured using handleError or try-catch

Actual result: The program crash without a way to capture the error

Details

<Include any other relevant details, logs, etc.>

Log:

Unhandled exception: Bad state: Cannot add event after closing #0 StreamController.add (dart:async/stream_controller.dart:595:24) #1 StreamSinkWrapper.add (dart:async/stream_controller.dart:867:13) #2 TransportStream.sendHeaders (package:http2/transport.dart:147:22) #3 ServerHandler.sendTrailers (package:grpc/src/server/handler.dart:361:13) #4 ServerHandler.sendError (package:grpc/src/server/handler.dart:410:5) #5 ServerHandler._onResponse (package:grpc/src/server/handler.dart:287:7) #6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10) #7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #8 _DelayedData.perform (dart:async/stream_impl.dart:591:14) #9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11) #10 _PendingEvents.schedule. (dart:async/stream_impl.dart:663:7) #11 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) #12 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5) #13 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:122:13) #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:193:5)

Process finished with exit code 255

I saw that the there is a comment above the method sendHeaders line 146 in the file .pub-cache/hosted/pub.dartlang.org/http2-2.0.0/lib/transport.dart saying // For convenience only.

So I have removed the call for it in the method sendTrailers line 361 in the file .pub-cache/hosted/pub.dartlang.org/grpc-3.0.2/lib/src/server/handler.dart And the crashes stopped.

guyluz11 avatar Jun 17 '22 13:06 guyluz11