Skip to content
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

fix(webSocket): manage serializer throwing exceptions #7114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

voliva
Copy link
Contributor

@voliva voliva commented Nov 11, 2022

Related issue (if exists):
Fixes #7111

Description:

I see the behaviour of the serializer was not really specified, I added a couple of tests to cover it.

This is the solution that's less disruptive with the previous behaviour:

  • If the serializer was throwing an object { code, reason } it won't be effected by this change: The socket will be closed with those parameters.
  • Otherwise, the socket is still getting closed, with the generic code 1000.
  • To not swallow the exception, I've rethrown it. This way the consumer can catch errors when sending them (as if it's sending a message with an incorrect format). For this I had to change SafeSubscriber to Subscriber, as it wasn't propagating the exception back to .next( caller.

I think all of this points are open for discussion though. A couple of questions:

  • Should the connection get closed when a message can't be serialized? Personally I think it shouldn't, but I didn't want to change this behaviour in this PR without discussing it.
  • Should the error happen on .next(, or should it be thrown on the observer? I think throwing them on .next( makes more sense, because it lets the producer know there was an exception. The observer expects errors to come only from the websocket.

@voliva voliva changed the title fix: manage serializer throwing exceptions. fix: manage serializer throwing exceptions on webSocket. Nov 11, 2022
@voliva voliva changed the title fix: manage serializer throwing exceptions on webSocket. fix(webSocket): manage serializer throwing exceptions Nov 12, 2022
Copy link
Member

@benlesh benlesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can accept this PR as-is. There's clearly a bug, but we need to discuss what the correct behavior is.

In general, the WebSocketSubject should emit the error... but also it seems like we should close the socket with the proper code when that happens.

spec/observables/dom/webSocket-spec.ts Outdated Show resolved Hide resolved
src/internal/observable/dom/WebSocketSubject.ts Outdated Show resolved Hide resolved
src/internal/observable/dom/WebSocketSubject.ts Outdated Show resolved Hide resolved
if (socket!.readyState === 1) {
try {
const { serializer } = this._config;
socket!.send(serializer!(x!));
} catch (e) {
this.destination!.error(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say the actual bug was here. We clearly have a handle to the wrong thing. 🤔

@benlesh benlesh added the blocked label Dec 3, 2022
@voliva voliva requested a review from benlesh December 15, 2022 11:58
@voliva
Copy link
Contributor Author

voliva commented Dec 16, 2022

Hey @benlesh I've just updated the PR with the decision taken at #7111. Can you take another look please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"WebSocketSubject.error must be called with an object with an error code" when serializer throws exception
2 participants