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

Cannot close event source from client side

Open mlesswing opened this issue 6 years ago • 3 comments

I receive an exception when trying to close an EventSource from the client side.

import 'package:eventsource/eventsource.dart'; ... EventSource sseClient; ... sseClient = await EventSource.connect( <VALID_URL> ]); ... sseClient.client.close();

Dart Error: Unhandled exception: Connection closed while receiving data

Note: I could not find a close() method on EventSource shown in the non-normative developer note of https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.

mlesswing avatar Feb 09 '19 16:02 mlesswing

Hmm, in all honesty, I kinda lost track of this package. If you can propose an implemented solution to your problem, I'd be very happy to read and accept it. I'd also be happy to accept fellow maintainers.

stevenroose avatar Feb 17 '19 22:02 stevenroose

Looking forward to a PR for this. Nice work, @rvowles !

aaronfg avatar Aug 02 '20 22:08 aaronfg

I use parts of this lib in a private experimental project and found a possible cause for this issue: The EventSourceDecoder doesn't forward the error-events from the original stream to the controller (i.e. a onError: controller.addError is missing). So the client is actually closed correctly, but this error is not handled and leads to a crash. However, I'm not sure how the downstream code (i.e. EventSource) would handle this error.

Since I don't consume the lib directly I don't plan to do a PR. But I wanted to left this as a note for anyone who is interested in fixing it. Took me quite some time to realize what led to the crash and the misleading error message.

dhenneke avatar Dec 07 '20 21:12 dhenneke