pratikbaid3 / flutter_client_sse

Dart package to help consume SSE API. Consumes server sent events by returning parsed model of the event, id, and the data
https://pub.dev/packages/flutter_client_sse
MIT License
41 stars 43 forks source link

When unsubscribe From SSE the _retryConnection method must stop #30

Open soufianebenyaala opened 3 weeks ago

soufianebenyaala commented 3 weeks ago

The error you are encountering occurs because you are attempting to add events to a StreamController that has already been closed. This issue is happening because unsubscribeFromSSE() closes the _streamController, but the SSEClient continues to try to add events to it.

Steps to Resolve the Issue

Check if the StreamController is Closed Before Adding Events: You can modify the code to check if the _streamController is closed before adding events. This will prevent the "Bad state: Cannot add new events after calling close" error.

Properly Handle the Stream Lifecycle:

Ensure that when you unsubscribe from SSE, no new events are being processed or added to the stream. After calling unsubscribeFromSSE(), you should stop any further attempts to subscribe to or retry the SSE connection.

pratikbaid3 commented 3 weeks ago

https://github.com/pratikbaid3/flutter_client_sse/pull/31