Repository navigation
feat: make the WebSocket close timeout configurable - #1486
Conversation
pjfanning
left a comment
There was a problem hiding this comment.
Thanks for this. A few points:
Tick interval now follows the setting. WebSocket.messageAPI still uses Source.tick(closeTimeout, closeTimeout, Tick) (WebSocket.scala:288, not in the diff), and that tick runs for the whole life of every connection, not just while closing. Before this PR it was fixed at 3s; now a small close-timeout such as 10ms makes every idle WebSocket push ~100 ticks/s through BypassMerge/FrameOutHandler, and a large one such as 60s lets a close take up to ~2x the setting because the deadline is only checked on a tick. Could the tick interval be decoupled from closeTimeout (e.g. min(closeTimeout, someCap) with a sensible floor), or the deadline driven by a timer started only when FrameOutHandler enters a closing state?
Docs. docs/src/main/paradox/client-side/websocket-support.md:99 still says the connection closes after "a timeout of 3 seconds". It would be good to mention close-timeout there.
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).
aa09d48 to
b237ff4
Compare
pjfanning
left a comment
There was a problem hiding this comment.
Thanks, this addresses all of my earlier points. The one-shot timer in FrameOutHandler is a nice improvement over the periodic tick. A few small follow-ups:
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).
b237ff4 to
05ca137
Compare
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).
05ca137 to
c5c75b4
Compare
c5c75b4 to
d4cd5a0
Compare
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: After the one-shot close timer in FrameOutHandler, nothing emits WebSocket.Tick any more, and the two-argument messageAPI overload had no callers and ignored its closeTimeout parameter. Modification: Remove `case object Tick` and the unused overload. Add a MiMa exclude for the removed internal Tick object. Result: No dead close-timeout code is left behind. Tests: - http-core/testOnly WebSocketClientSpec WebSocketServerSpec ClientConnectionSettingsSpec: 111 passed - http-core/mimaReportBinaryIssues: passed References: Refs apache#1486
|
I rebased this onto |
Motivation: Allow applications to configure the existing three-second graceful close wait without adding periodic work on open WebSocket connections. Modification: Add bounded finite client and server close-timeout settings with Java and Scala APIs. Start a one-shot timer only on entering the close wait and share the client's original budget across peer response and transport closure. Preserve the three-second default. Include PJ Fanning's cleanup from d4cd5a0: remove the obsolete internal Tick and unused messageAPI overload, with an exact MiMa filter for the removed Tick class. Result: No periodic close-wait ticks are emitted. The timeout is subject to scheduler granularity, not a hard end-to-end wall-clock bound. Tests: - Historical focused WebSocket and settings suites: PJ reported 111 passing and http-core/mimaReportBinaryIssues passing on the previous head. - Mechanical replay on current main matches the independently calculated merge tree. All 12 changed files are byte-identical to the previous head. - git diff --check passed. No new full build, test suite, MiMa or CI run. References: Refs apache#1486, Netty #8896 and #9967 (context only; independent implementation).
d4cd5a0 to
c537a9e
Compare
Motivation: An invalid `close-timeout` in config failed in two different ways: `infinite` threw a ConfigurationException naming the setting, while a zero, negative or over-1-hour value fell through to the settings constructor's `require` and surfaced as an IllegalArgumentException that does not name the setting. The server test "when user handler instantly tries to send messages" had also been renamed and switched to a 750ms close timeout, although it never checks close timing, so that scenario was no longer covered with the default settings. Modification: Validate the range in `readCloseTimeout` and throw a ConfigurationException naming `close-timeout` for every invalid config value. The constructor's `require` stays for programmatic use. Restore the server test to its original name and default settings. The configured close wait is covered by the separate "use the configured close wait when the peer delays its close response" test. Result: Every invalid configured `close-timeout` is reported as a ConfigurationException that names the setting, and the default 3s close timeout path keeps its original server test. Tests: - sbt "http-core / Test / testOnly org.apache.pekko.http.scaladsl.settings.ClientConnectionSettingsSpec org.apache.pekko.http.impl.engine.ws.WebSocketServerSpec": 81 passed, 7 pending - sbt "http-core / scalafmtAll": no further changes - sbt "http-core / mimaReportBinaryIssues": passed - git diff --check: clean References: Refs apache#1486
Motivation: Allow applications to configure the existing three-second graceful close wait without adding periodic work on open WebSocket connections. Modification: Add bounded finite client and server close-timeout settings with Java and Scala APIs. Start a one-shot timer only on entering the close wait and share the client's original budget across peer response and transport closure. Preserve the three-second default. Include PJ Fanning's cleanup from d4cd5a0: remove the obsolete internal Tick and unused messageAPI overload, with an exact MiMa filter for the removed Tick class. Result: No periodic close-wait ticks are emitted. The timeout is subject to scheduler granularity, not a hard end-to-end wall-clock bound. Tests: - Historical focused WebSocket and settings suites: PJ reported 111 passing and http-core/mimaReportBinaryIssues passing on the previous head. - Mechanical replay on current main matches the independently calculated merge tree. All 12 changed files are byte-identical to the previous head. - git diff --check passed. No new full build, test suite, MiMa or CI run. References: Refs #1486, Netty #8896 and #9967 (context only; independent implementation).
Motivation
Allow applications to configure the existing three-second graceful close
wait without adding periodic work on open WebSocket connections.
Modification
Add bounded finite client and server close-timeout settings with Java and
Scala APIs. Start a one-shot timer only on entering the close wait and
share the client's original budget across peer response and transport
closure. Preserve the three-second default.
Include PJ Fanning's cleanup from d4cd5a0:
remove the obsolete internal Tick and unused messageAPI overload, with an
exact MiMa filter for the removed Tick class.
Result
No periodic close-wait ticks are emitted. The timeout is subject to
scheduler granularity, not a hard end-to-end wall-clock bound.
Tests
and http-core/mimaReportBinaryIssues passing on the previous head.
merge tree. All 12 changed files are byte-identical to the previous head.
References
Refs #1486, Netty #8896 and #9967 (context only; independent implementation).