-
Notifications
You must be signed in to change notification settings - Fork 58
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
websocketpeer: don't crash if Close() called multiple times #313
websocketpeer: don't crash if Close() called multiple times #313
Conversation
6c729ef
to
2798a81
Compare
9609aab
to
d126d1c
Compare
title should be "websocketpeer: don't crash if Close() called multiple times" |
"github.com/gammazero/nexus/v3/wamp" | ||
) | ||
|
||
func TestCloseWebsocketPeer(t *testing.T) { |
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.
instead of starting a router and creating a websocket connection you should just mock websocket connection. You test will look something like
func TestCloseWebsocketPeer(t *testing.T) {
logger := log.Default()
peer := transport.NewWebsocketPeer(newMockSession(), &serialize.JSONSerializer{}, 1, logger, 0, 0)
// Close the client connection.
peer.Close()
// Try closing the client connection again. It should not cause an error.
peer.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.
Done
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.
Looks good now. This fixes a real crash in the router.
@KSDaemon This fixes a panic when close is called twice on the WebSocketPeer. Would make sense to land it |
@muzzammilshahid @om26er Can you show the practical use cases when that happens? I mean when you have to call |
@KSDaemon I am facing this issue while attempting a progressive call, if the caller does not support
|
@muzzammilshahid Well, okay. But this doesn't answer the question of why the second (or I would say: more than one) |
@KSDaemon When dealer closes the session Line 410 in 6e73a60
Line 429 in 6e73a60
Line 432 in 6e73a60
Line 410 in 6e73a60
|
This happens when a client makes "progressive call invocations" even though it has not announced that. In that case the dealer sends the abort and closes the session Line 660 in 6e73a60
As a consequence of that the inbound message reader exits and tries to close the session Line 397 in 6e73a60
In any case calling WebsocketPeer.Close() should never cause a crash/panic. |
Thnx guys for the explanation! I'm afk for a weekend! I'll look deeper and probably merge in a few days! |
Description, Motivation and Context
Refactor Close method in websocketPeer to handle duplicate close calls.
What is the current behavior?
The router crashes on duplicate close call.
What is the new behavior?
Duplicate close calls are handled.
What kind of change does this PR introduce?
Checklist: