WebSocket client handshaker to support "force close" after timeout#8896
WebSocket client handshaker to support "force close" after timeout#8896normanmaurer merged 1 commit intonetty:4.1from
Conversation
|
Can one of the admins verify this patch? |
|
@kachayev its RFC6455 ;) |
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
...ttp/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java
Outdated
Show resolved
Hide resolved
...ttp/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java
Outdated
Show resolved
Hide resolved
...ttp/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java
Outdated
Show resolved
Hide resolved
...ttp/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java
Outdated
Show resolved
Hide resolved
@normanmaurer Copy-paste error ;) |
326620a to
1e91a34
Compare
|
@normanmaurer Updated. I still think if need to cover this use case: 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. |
|
@kachayev another alternative would be to allow to overload the method with a timeout. |
1e91a34 to
c150a74
Compare
|
@normanmaurer Added setter to cover more use cases. Changed test to use an internal flag that indicated that the timeout was actually fired. |
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
...ttp/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketHandshakeHandOverTest.java
Outdated
Show resolved
Hide resolved
abac67d to
cd8b306
Compare
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
cd8b306 to
be40c4e
Compare
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
be40c4e to
f88cc9b
Compare
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java
Outdated
Show resolved
Hide resolved
f88cc9b to
481d380
Compare
|
/cc @vietj |
|
@netty-bot test this please |
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
481d380 to
a3407f5
Compare
|
@netty-bot test this please |
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
a3407f5 to
d770d0b
Compare
|
@netty-bot test this please |
|
@trustin can you have a look as well please ? |
|
@netty-bot test this please |
Probably better enabling by default with reasonable default? Leaky connection for backward compatibility doesn't sound right to me. |
|
@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 ? |
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java
Outdated
Show resolved
Hide resolved
|
Not a WebSocket expert. 😅 Leaving it up to @kachayev 😆 |
|
@slandelle can you have a look as well ? |
Absolutely, 100% for it. I will put 10 seconds to stay consistent with SSL handshake timeouts. |
slandelle
left a comment
There was a problem hiding this comment.
2 small nits. LGTM otherwise!
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Outdated
Show resolved
Hide resolved
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.
d770d0b to
d6795c4
Compare
|
@trustin @slandelle Pushed changes, thanks for the review! |
|
@trustin PTAL again |
|
@netty-bot test this please |
|
@kachayev thanks a lot! |
…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.
…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).
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
Modifications:
WebSocket client handshaker additional param
forceCloseAfterMillisSwitched 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
WebSocketClientHandshakerfunctionality, not in handlers, as far as it's responsible forclose.Nothing prevents you to call
handshaker.closetwice, 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?