stevenroose / dart-eventsource

A client and server implementation of Server-Side Events.
MIT License
56 stars 49 forks source link

Cannot close event source from client side #9

Open mlesswing opened 5 years ago

mlesswing commented 5 years ago

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( ]); ... 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.

stevenroose commented 5 years ago

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.

aaronfg commented 3 years ago

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

dhenneke commented 3 years ago

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.