-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add retry logic #17
Add retry logic #17
Conversation
lib/client/sse_client.dart
Outdated
if (!(_errorTimer?.isActive ?? false)) { | ||
// By default the SSE client uses keep-alive. | ||
// Allow for a retry to connect before giving up. | ||
_errorTimer = Timer(const Duration(seconds: 5), () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did 5 seconds come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a number that has worked well in practice for internal systems. Realistically the event source reconnect should be sub second. This gives plenty of overhead.
lib/client/sse_client.dart
Outdated
/// [serverUrl] is the URL under which the server is listening for | ||
/// incoming bi-directional SSE connections. | ||
SseClient(String serverUrl) { | ||
SseClient(String serverUrl, {bool withRetry}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
synced offline - since all of our known use cases will want to use retry I think we can roll to version 3.0.0 and make it non-optional. This package shouldn't have an overwhelming amount of churn to bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
- Add retry logic. | ||
|
||
** Possible Breaking Change ** Error messages may now be delayed up to 5 seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we say "Error messages for disconnects"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General error messages may be delayed as we have no way to make a distinction.
Unfortunately I don't have a good way to test the retry logic in a unit test. Open to suggestions. Went ahead and added the option to ensure we didn't regress on current tests.
Note we now close the
eventSource
on error as it continually attempts to reconnect. Somewhat related to dart-lang/webdev#818.