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

Issue #3494 - flaky tests in jetty-websocket-tests ClientCloseTest #3521

Merged

Conversation

lachlan-roberts
Copy link
Contributor

#3494

Nulling out values in WebSocketAdapter causes race conditions when trying to access session and endpoint externally which was causing errors in the tests, if you call adapter.getSession().close() the socket could receive a close just before null out the session and then you get a NPE

There was a race condition in WebSocketChannel.Flusher.onCompleteFailure(), where processConnectionError() should be called before super.onCompleteFailure() to ensure that the
correct close reason is processed before the channel is closed.

In testWriteException when the output was shutdown there was a race condition between the client detecting the write failure and the server detecting a read failure and sending a failure response.
We now send a message to block the server from reading so that it will not detect the failure and respond.

Nulling out values in WebSocketAdapter causes race conditions when
trying to access session and endpoint externally

Race condition in WebSocketChannel.Flusher.onCompleteFailure(),
processConnectionError should be called first to ensure that the
correct close reason is processed, super.onCompleteFailure() was closing
the connection causing a read failure.

race condition between the server detecting a read failure and sending
a response and the client detecting the write failure, now blocking
on the server so it is not reading and will not detect the failure

Signed-off-by: lachan-roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
…rror

WebSocketChannel.processConnectionError now defaults to NO_CLOSE
status if no protocol reasons can be found

added some debug logging

improvements to tests

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

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

Minor niggles, not worth impacting this PR, but should probably be addressed elsewhere.

@@ -59,8 +59,7 @@ public void onWebSocketBinary(byte[] payload, int offset, int len)
@Override
public void onWebSocketClose(int statusCode, String reason)
{
this.session = null;
this.remote = null;
/* do nothing */
Copy link
Contributor

Choose a reason for hiding this comment

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

If we go this route, then we MUST make sure that the session / remote are not capable of being used after onWebSocketClose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using the session after the close has happened will result in Session.isOpen() returning false and any writes on the RemoteEndpoint are failed, so they are safe to keep around after the close
although maybe we need test cases to verify this behaviour

@lachlan-roberts
Copy link
Contributor Author

@joakime I don't have the permissions to merge, so can you merge it if there's no further changes you want

…-3494-clientclosetest

Signed-off-by: lachan-roberts <lachlan@webtide.com>
@lachlan-roberts lachlan-roberts force-pushed the jetty-10.0.x-3494-clientclosetest branch from 0094dba to 002ecf5 Compare April 9, 2019 08:21
@joakime joakime merged commit 578e5d5 into jetty:jetty-10.0.x Apr 10, 2019
@lachlan-roberts lachlan-roberts deleted the jetty-10.0.x-3494-clientclosetest branch July 1, 2019 08:07
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