Skip to content

Fix close edge cases#1908

Merged
lpinca merged 2 commits intomasterfrom
fix/close-edge-cases
Jun 28, 2021
Merged

Fix close edge cases#1908
lpinca merged 2 commits intomasterfrom
fix/close-edge-cases

Conversation

@lpinca
Copy link
Copy Markdown
Member

@lpinca lpinca commented Jun 25, 2021

Ensure that socket.end() is called if an error occurs simultaneously on
both peers.

Refs: #1902

lpinca and others added 2 commits June 26, 2021 07:13
Ensure that `socket.end()` is called if an error occurs simultaneously
on both peers.

Refs: #1902
@lpinca lpinca force-pushed the fix/close-edge-cases branch from bdfb346 to 614aa04 Compare June 26, 2021 06:27
if (this._closeFrameSent && this._closeFrameReceived) this._socket.end();
if (
this._closeFrameSent &&
(this._closeFrameReceived || this._receiver._writableState.errorEmitted)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@pimterry I think that adding this._receiver._writableState.finished here and below along with the -2 ready state would also address #1902 (comment).

Anyway I would prefer to keep it as is because:

  1. A socket 'end' event with no close frame means that the remote peer is doing something wrong.
  2. We are consistent with browsers behavior. The connection is closed immediately with no close frame sent back.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I'm convinced! 👍 Given all the extra complexity involved and that the spec doesn't mind either way, in the case where the remote peer half-closes their end unexpectedly I think it's totally reasonable to drop all our outgoing data, fully close the socket, and treat it as an abnormal websocket close.

if (this._closeFrameSent && this._closeFrameReceived) this._socket.end();
if (
this._closeFrameSent &&
(this._closeFrameReceived || this._receiver._writableState.errorEmitted)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I'm convinced! 👍 Given all the extra complexity involved and that the spec doesn't mind either way, in the case where the remote peer half-closes their end unexpectedly I think it's totally reasonable to drop all our outgoing data, fully close the socket, and treat it as an abnormal websocket close.


if (
this._closeFrameReceived ||
this._receiver._writableState.errorEmitted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpicking: since both of these checks are effectively the same (sent is just omitted here because we know it's true) it might be clearer if this gets extracted into some _connectionCompleted() internal method, so that the logic here is a bit clearer and easier to check in future.

Doesn't affect the functionality either way of course, so up to you, it'd just make it a bit easier to tell what's going on.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it makes sense. I'll keep it as is now as I can't think of a good name for the function and eventually change it later.

@lpinca lpinca merged commit 2916006 into master Jun 28, 2021
@lpinca lpinca deleted the fix/close-edge-cases branch June 28, 2021 19:08
@lpinca
Copy link
Copy Markdown
Member Author

lpinca commented Jun 28, 2021

Thank you for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants