Skip to content

WebSocket client handshaker to support "force close" after timeout#8896

Merged
normanmaurer merged 1 commit intonetty:4.1from
kachayev:ft-websocket-force-close
Apr 10, 2019
Merged

WebSocket client handshaker to support "force close" after timeout#8896
normanmaurer merged 1 commit intonetty:4.1from
kachayev:ft-websocket-force-close

Conversation

@kachayev
Copy link
Copy Markdown
Contributor

@kachayev kachayev commented Feb 27, 2019

Motivation:

RFC 6455 defines that, generally, a WebSocket client should not close a TCP
connection as far as a server is the one who's responsible for doing that.
In practice tho', it's not always possible to control the server. Server's
misbehavior may lead to connections being leaked (if the server does not
comply with the RFC).

RFC 6455 #7.1.1 says

In abnormal cases (such as not having received a TCP Close from the server
after a reasonable amount of time) a client MAY initiate the TCP Close.

Modifications:

  • WebSocket client handshaker additional param forceCloseAfterMillis

  • Switched off by default to keep backward compatibility

Result:

WebSocket client handshaker to comply with RFC. Fixes #8883.


Open questions/comments:

  • I've implemented this as a WebSocketClientHandshaker functionality, not in handlers, as far as it's responsible for close.

  • Nothing prevents you to call handshaker.close twice, in such a case only first timeout would be applied.

  • Do we need to keep this feature switched OFF by default to ensure backward compatibility? I mean... it's hard to justify current implementation and I think 10 seconds default timeout should be enough to cover potential drawbacks. @normanmaurer WDYT?

  • Testing is kind of clumsy... It's impossible to detect if the channel was closed because of timeout or because of the server or... whatever. Maybe I'm missing any better approach to test this?

@netty-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@normanmaurer
Copy link
Copy Markdown
Member

@kachayev its RFC6455 ;)

@kachayev
Copy link
Copy Markdown
Contributor Author

@kachayev its RFC6455 ;)

@normanmaurer Copy-paste error ;)

@kachayev kachayev force-pushed the ft-websocket-force-close branch 2 times, most recently from 326620a to 1e91a34 Compare February 28, 2019 13:21
@kachayev
Copy link
Copy Markdown
Contributor Author

@normanmaurer Updated. I still think if need to cover this use case:

handshaker.setForceCloseTimeoutMillis(1_000).close(ch, new CloseWebsocketFrame());

It might be useful if the timeout depends on what happened during the communication (then I have no chance to setup it properly before the upgrade)... I just don't know how often you might need this in practice.

@normanmaurer
Copy link
Copy Markdown
Member

@kachayev another alternative would be to allow to overload the method with a timeout.

@kachayev kachayev force-pushed the ft-websocket-force-close branch from 1e91a34 to c150a74 Compare February 28, 2019 14:14
@kachayev
Copy link
Copy Markdown
Contributor Author

@normanmaurer Added setter to cover more use cases. Changed test to use an internal flag that indicated that the timeout was actually fired.

@kachayev kachayev force-pushed the ft-websocket-force-close branch 2 times, most recently from abac67d to cd8b306 Compare February 28, 2019 20:17
@kachayev kachayev force-pushed the ft-websocket-force-close branch from cd8b306 to be40c4e Compare March 1, 2019 08:27
@kachayev kachayev force-pushed the ft-websocket-force-close branch from be40c4e to f88cc9b Compare March 1, 2019 21:49
@kachayev kachayev force-pushed the ft-websocket-force-close branch from f88cc9b to 481d380 Compare March 5, 2019 09:30
@normanmaurer
Copy link
Copy Markdown
Member

/cc @vietj

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@kachayev kachayev force-pushed the ft-websocket-force-close branch from 481d380 to a3407f5 Compare March 14, 2019 21:41
@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

Copy link
Copy Markdown
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

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

LGTM... just one nit

@kachayev kachayev force-pushed the ft-websocket-force-close branch from a3407f5 to d770d0b Compare March 15, 2019 14:13
@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer normanmaurer requested a review from trustin March 26, 2019 08:20
@normanmaurer
Copy link
Copy Markdown
Member

@trustin can you have a look as well please ?

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@trustin
Copy link
Copy Markdown
Member

trustin commented Apr 1, 2019

Switched off by default to keep backward compatibility

Probably better enabling by default with reasonable default? Leaky connection for backward compatibility doesn't sound right to me.

@normanmaurer
Copy link
Copy Markdown
Member

@trustin sounds fine to me... maybe 3 seconds (which is also the default we use for SSL close notify) is ok ? Or do we want to use 10 seconds as we use for handshake timeout in SSL by default ?

Copy link
Copy Markdown
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Mostly nits.

@trustin
Copy link
Copy Markdown
Member

trustin commented Apr 1, 2019

Not a WebSocket expert. 😅 Leaving it up to @kachayev 😆

@normanmaurer
Copy link
Copy Markdown
Member

@slandelle can you have a look as well ?

@kachayev
Copy link
Copy Markdown
Contributor Author

kachayev commented Apr 1, 2019

@trustin

enabling by default

Absolutely, 100% for it. I will put 10 seconds to stay consistent with SSL handshake timeouts.

Copy link
Copy Markdown
Contributor

@slandelle slandelle left a comment

Choose a reason for hiding this comment

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

2 small nits. LGTM otherwise!

Motivation:

RFC 6455 defines that, generally, a WebSocket client should not close a TCP
connection as far as a server is the one who's responsible for doing that.
In practice tho', it's not always possible to control the server. Server's
misbehavior may lead to connections being leaked (if the server does not
comply with the RFC).

RFC 6455 netty#7.1.1 says

> In abnormal cases (such as not having received a TCP Close from the server
after a reasonable amount of time) a client MAY initiate the TCP Close.

Modifications:

* WebSocket client handshaker additional param `forceCloseAfterMillis`

* Switched of by default to keep backward compatibility

Result:

WebSocket client handshaker to comply with RFC. Fixes netty#8883.
@kachayev kachayev force-pushed the ft-websocket-force-close branch from d770d0b to d6795c4 Compare April 2, 2019 05:30
@kachayev
Copy link
Copy Markdown
Contributor Author

kachayev commented Apr 2, 2019

@trustin @slandelle Pushed changes, thanks for the review!

@normanmaurer
Copy link
Copy Markdown
Member

@trustin PTAL again

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer normanmaurer self-assigned this Apr 10, 2019
@normanmaurer normanmaurer merged commit ee351ef into netty:4.1 Apr 10, 2019
@normanmaurer
Copy link
Copy Markdown
Member

@kachayev thanks a lot!

normanmaurer pushed a commit that referenced this pull request Apr 10, 2019
…8896)

Motivation:

RFC 6455 defines that, generally, a WebSocket client should not close a TCP
connection as far as a server is the one who's responsible for doing that.
In practice tho', it's not always possible to control the server. Server's
misbehavior may lead to connections being leaked (if the server does not
comply with the RFC).

RFC 6455 #7.1.1 says

> In abnormal cases (such as not having received a TCP Close from the server
after a reasonable amount of time) a client MAY initiate the TCP Close.

Modifications:

* WebSocket client handshaker additional param `forceCloseAfterMillis`

* Use 10 seconds as default

Result:

WebSocket client handshaker to comply with RFC. Fixes #8883.
alfred-yeung added a commit to riptano/netty that referenced this pull request May 28, 2022
…etty#8896)

Motivation:
RFC 6455 defines that, generally, a WebSocket client should not close a TCP
connection as far as a server is the one who's responsible for doing that.
In practice tho', it's not always possible to control the server. Server's
misbehavior may lead to connections being leaked (if the server does not
comply with the RFC).

RFC 6455 #7.1.1 says

In abnormal cases (such as not having received a TCP Close from the server
after a reasonable amount of time) a client MAY initiate the TCP Close.

Modifications:
WebSocket client handshaker additional param forceCloseAfterMillis

Switched off by default to keep backward compatibility

Result:
WebSocket client handshaker to comply with RFC. Fixes (netty#8883).
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.

Websocket client closing handshake to support "force close" after given timetout

5 participants