-
Notifications
You must be signed in to change notification settings - Fork 127
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
Handle Web Socket error #324
Conversation
|
||
// RxJS.retryWhen has a bug that would cause "error" signal to be sent after the observable is completed/errored. | ||
// We need to guard against extraneous "error" signal to workaround the bug. | ||
closed || subscriber.error(close); |
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.
error [](start = 37, length = 5)
normal web socket close should lead to non-error RX stream completion, right?
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.
I am keeping the original logic as-is, i.e. onclose
will throw an error. And I think it's intentional.
If you look at line 910,
BotFramework-DirectLineJS/src/directLine.ts
Line 912 in 6fc932d
// WebSockets can be closed by the server or the browser. In the former case we need to |
this.observableWebSocket<ActivityGroup>()
// WebSockets can be closed by the server or the browser. In the former case we need to
// retrieve a new streamUrl. In the latter case we could first retry with the current streamUrl,
// but it's simpler just to always fetch a new one.
.retryWhen(error$ => error$.delay(this.getRetryDelay(), this.services.scheduler).mergeMap(error => this.reconnectToConversation()))
Looks like the author of the logic intentionally want to retry whenever the server or browser close the connection. And to do that, the code need to throw error on graceful close.
What do you think?
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.
🕐
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.
Reintroducing PR #170 and workarounding RxJS issue.
There is a bug in RxJS
retryWhen
operator that caused observable to be re-subscribed more than once, after only one error is raised. That means, the RxJS bug could cause one error to trigger reconnect twice.We wrote a test case that:
Without
onerror
Within 2 seconds, we are seeing 88 errors injected, and 88 reconnections.
With
onerror
Within 2 seconds, we are seeing 767 errors injected, and 1023 reconnections.
Takeaways:
To mitigate, we manually added a flag
closed
. This flag guardobserver.error()
will only be called once. We believe if itobserver.error()
is called twice (byonerror
, followed byonclose
event),retryWhen
could triggered retry twice (or more).We added a test case to make sure all numbers are under control in the future.