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

stop client websocket close echoing server close #10382

Merged
merged 1 commit into from Jun 10, 2016

Conversation

@bobthekingofegypt
Copy link
Contributor

bobthekingofegypt commented Apr 3, 2016

Client initiated close requests should send a close message to the
server that the server will echo back to complete the process. Servo
should not then echo the servers close request back again to the server,
this guard stops servo from echoing a server close request if the
process was initiated by the client.

Tracked in #9803 (comment)


This change is Reviewable

@highfive
Copy link

highfive commented Apr 3, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/websocket_loader.rs
@highfive
Copy link

highfive commented Apr 3, 2016

warning Warning warning

  • These commits modify net code, but no tests are modified. Please consider adding a test!
@@ -123,7 +126,9 @@ pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData, c
},
Type::Pong => continue,
Type::Close => {
ws_sender_incoming.lock().unwrap().send_message(&message).unwrap();
if client_initiated_close_incoming.load(Ordering::SeqCst) == false {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Apr 3, 2016

Member

nit: if !client_initiated_close_incoming.load(Ordering::SeqCst) {

@metajack
Copy link
Contributor

metajack commented Apr 4, 2016

r=me with @KiChjang's comment addressed


Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@metajack
Copy link
Contributor

metajack commented Apr 4, 2016

Reviewed 1 of 1 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@bobthekingofegypt
Copy link
Contributor Author

bobthekingofegypt commented Apr 4, 2016

@KiChjang's comment addressed.

@metajack
Copy link
Contributor

metajack commented Apr 4, 2016

@bors-servo r+


Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Apr 4, 2016

📌 Commit cbfc36d has been approved by metajack

@metajack
Copy link
Contributor

metajack commented Apr 4, 2016

@bors-servo r-

Please squash and we'll get this merged.

+S-needs-squash


Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@bobthekingofegypt
Copy link
Contributor Author

bobthekingofegypt commented Apr 4, 2016

Sorry, I'll need to add the guard around https://github.com/bobthekingofegypt/servo/blob/fix-websocket-close/components/net/websocket_loader.rs#L160 as well. As it's still possible to send two close messages. Will get it done tomorrow.

@bobthekingofegypt
Copy link
Contributor Author

bobthekingofegypt commented Apr 10, 2016

Sorry for the delay, I added the check around both incoming and outgoing. If it's ok, I'll squash all the commits.

@jdm jdm removed the S-needs-squash label Apr 13, 2016
@metajack
Copy link
Contributor

metajack commented Apr 13, 2016

Looks good, aside from the comment I left. You can go ahead and squash it at the same time you address that.


Reviewed 1 of 1 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


components/net/websocket_loader.rs, line 129 [r3] (raw file):
If we weren't waiting for the close to come in, we now set that we are. When we aren't waiting for a close, getting a close needs a ack. By sending this ack, we should not be getting an ack to our ack, nor did we send a client intiated close. So I'm not sure why you are toggling the bool in this case.


Comments from Reviewable

@perlun
Copy link
Contributor

perlun commented Apr 22, 2016

@bobthekingofegypt - any progress on this one?

@bobthekingofegypt
Copy link
Contributor Author

bobthekingofegypt commented Apr 23, 2016

I can't really use computers at the moment due to an issue with my eye. So I can't really deal with this right now. I hope to be back to normal in a few weeks.

In response to your comment @metajack the reason that the boolean is checked and updated on both incoming and outgoing threads is due to the current threading.
From memory without checking anything it is to do with the websocket server initiating a close and the user script on servo side calling close at the same time, happens a lot on the test cases.
Whatever happens you only want to send one close whether it is an initiator or an echo, the boolean check and update on both means only one close with ever be sent regardless of the order the threads are executed.

I can write up a better explanation when I'm back but I'm just rushing this comment for now. If someone else wants to wrap this up feel free.

@bobthekingofegypt
Copy link
Contributor Author

bobthekingofegypt commented May 6, 2016

components/net/websocket_loader.rs, line 129 [r3] (raw file):
Sorry, I think I misunderstood this when I replied in the PR. I'm still not sure I fully understand. I think I may have confused things by naming the variable initiated_close rather than something like sent_close.
I flip the guard here as well as down below because I only want to send a close once, regardless of whether it is an echo or an instigator. If I don't flip the guard here then a JS call to close the websocket can still trigger another close event through line 155 as the state on dom/websocket side is not yet marked as closed or closing.


Comments from Reviewable

@jdm
Copy link
Member

jdm commented Jun 8, 2016

The code and explanation makes sense to me. @bobthekingofegypt if you squash the commits, I'll merge it :)

@jdm jdm unassigned metajack Jun 8, 2016
@jdm jdm self-assigned this Jun 8, 2016
@jdm jdm added S-needs-squash and removed S-awaiting-review labels Jun 8, 2016
@jdm jdm unassigned metajack Jun 8, 2016
@metajack
Copy link
Contributor

metajack commented Jun 8, 2016

I'm not sure how I forgot to comment here. I could have sworn I wrote out an r=me.

In any case, I apologize for the delay and I agree with jdm.

Need to make sure close is only sent to the server once, either from a
client initiation or from a server echo.  This adds the sent check to
both incoming and outgoing threads.
@bobthekingofegypt bobthekingofegypt force-pushed the bobthekingofegypt:fix-websocket-close branch from 97c58fc to 27b4ac6 Jun 10, 2016
@highfive
Copy link

highfive commented Jun 10, 2016

New code was committed to pull request.

@jdm
Copy link
Member

jdm commented Jun 10, 2016

@bors-servo: r=metajack

@bors-servo
Copy link
Contributor

bors-servo commented Jun 10, 2016

📌 Commit 27b4ac6 has been approved by metajack

@bors-servo
Copy link
Contributor

bors-servo commented Jun 10, 2016

Testing commit 27b4ac6 with merge 96f3404...

bors-servo added a commit that referenced this pull request Jun 10, 2016
stop client websocket close echoing server close

Client initiated close requests should send a close message to the
server that the server will echo back to complete the process.  Servo
should not then echo the servers close request back again to the server,
this guard stops servo from echoing a server close request if the
process was initiated by the client.

Tracked in #9803 (comment)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10382)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 10, 2016

@bors-servo bors-servo merged commit 27b4ac6 into servo:master Jun 10, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.