Repository navigation
WebSocket client handshaker to support "force close" after timeout - #8896
Conversation
|
Can one of the admins verify this patch? |
|
@kachayev its RFC6455 ;) |
@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. |
abac67d to
cd8b306
Compare
cd8b306 to
be40c4e
Compare
be40c4e to
f88cc9b
Compare
f88cc9b to
481d380
Compare
|
/cc @vietj |
|
@netty-bot test this please |
481d380 to
a3407f5
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 ? |
|
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!
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: WebSocket close waits currently use a fixed three-second setting and a periodic tick, even while connections are not closing. Applications need to tune close-handshake waits without changing other timeout settings. Modification: Expose the positive client/server close timeout (maximum one hour) via config and the Scala and Java settings APIs. Preserve three seconds by default and for legacy config snippets. Arm a one-shot timer only while waiting for peer Close or transport closure; keep the original budget for a client transitioning between those phases. Keep the legacy stack entry points and default getter, route settings-aware callers through the configured value, use the shared Java duration converter, and document the client behavior. Result: Both endpoints honor the configured wait with no periodic work on open connections. Existing idle timeout semantics are unchanged. Timer delivery remains subject to scheduler granularity. Tests: - Strict Scala 2.13.18 compilation of the six affected production sources and three affected specifications against cached dependencies: passed. - Eight settings cases and two directional client/server close cases: passed; both directional cases fail against original-main wiring. - Targeted MiMa against the exact baseline: zero findings. - Cached Scalafmt and git diff --check: passed. - Full repository CI and cross-Scala build not run locally. References: Refs apache#1486 and Netty netty/netty#8896, netty/netty#9967 (independent Pekko implementation).
Motivation: Allow applications to tune the current fixed three-second close wait without changing the idle timeout or adding work to open connections. Modification: Configure the client and server close wait with Scala and Java settings and a finite positive range up to one hour. Arm one timer while closing; reuse the remaining time when an active client receives the peer Close but still waits for transport closure. Route standard stack calls through settings and remove the dead internal tick and default getter. Keep the legacy messageAPI parameter with an explicit unused annotation. Document the default, bounds and scheduler granularity. Result: Normal traffic has no periodic close check, and a client's two closing phases share one configured budget. The default remains three seconds. Tests: - Strict Scala 2.13.18 production/test compile against cached modules. - Eight settings cases and normal client/server configurable close cases passed in the first review round; the old wiring fails both. - Current focused client configurable close and shared-budget cases passed; the shared-budget case fails when the timer restarts. - Targeted MiMa with a freshly compiled source baseline reports zero. Two obsolete implementation-only symbols are intentionally removed. - Scalafmt and git diff --check passed; full CI not run locally. References: Refs apache#1486, netty/netty#8896 and netty/netty#9967 (independent implementation).
Motivation: Allow applications to tune the fixed three-second close wait without changing the idle timeout or adding work to open connections. Modification: Configure the client and server close wait with Scala and Java settings and a finite positive range up to one hour. Arm one timer while closing and reuse its remaining time after the peer Close reply. Route stack calls through settings and remove the obsolete internal stack default getter. Keep the legacy messageAPI overload and retain Tick only as an ABI symbol from 2.0.0; do not schedule or emit it. Qualify the Java getter's Scala value explicitly for cross-version compilation. Result: Open connections no longer receive periodic close checks; the client's two closing phases share one budget. The default remains three seconds. Tests: - Changed sources compiled in Scala 2.13.18; eight settings and two focused client cases passed against the rebuilt classes. - The three affected settings sources compiled on Scala 3.3.9 and 3.9.0 against published dependencies; the unqualified getter reproduced E049. - Targeted MiMa with the 2.0.0 artifact and rebuilt classes reproduced the missing Tick symbol, then reported zero problems with the fix. - Scalafmt and git diff --check passed. The cloud JDK lacks the Java 17 release symbols required by the unchanged aggregate build; full CI is not claimed locally. References: Refs apache#1486, netty/netty#8896 and netty/netty#9967 (independent implementation).
Motivation: Allow applications to tune the fixed three-second close wait without changing the idle timeout or adding work to open connections. Modification: Configure the client and server close wait with Scala and Java settings and a finite positive range up to one hour. Arm one timer while closing and reuse its remaining time after the peer Close reply. Route stack calls through settings and remove the obsolete internal stack default getter. Keep the legacy messageAPI overload and retain Tick only as an ABI symbol from 2.0.0; do not schedule or emit it. Qualify the Java getter's Scala value explicitly for cross-version compilation. Result: Open connections no longer receive periodic close checks; the client's two closing phases share one budget. The default remains three seconds. Tests: - Changed sources compiled in Scala 2.13.18; eight settings and two focused client cases passed against the rebuilt classes. - The three affected settings sources compiled on Scala 3.3.9 and 3.9.0 against published dependencies; the unqualified getter reproduced E049. - Targeted MiMa with the 2.0.0 artifact and rebuilt classes reproduced the missing Tick symbol, then reported zero problems with the fix. - Scalafmt and git diff --check passed. The cloud JDK lacks the Java 17 release symbols required by the unchanged aggregate build; full CI is not claimed locally. References: Refs apache#1486, netty/netty#8896 and netty/netty#9967 (independent implementation).
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?