Repository navigation
Avoid premature HTTP/2 ping timeouts after scheduler pauses - #1462
Conversation
pjfanning
left a comment
There was a problem hiding this comment.
Thanks, the fix makes sense. The ack timeout is counted in ticks, so the catch-up burst that fixed-rate scheduling produces after a pause can use up the whole timeout window right after a ping is sent. Fixed delay avoids that. The trade-off is that ticks drift later under load, which only makes the ping interval and timeout longer than configured, never shorter. That's the safe direction. The PausedScheduler regression is a nice deterministic way to show it. A few points:
- Reference to akka/akka-http#4182. That PR was merged in November 2022, after Akka's licence change, so it's BSL-licensed. Pekko shouldn't derive changes from post-licence-change Akka code. The change here is a one-word scheduling choice with its own reasoning in the description, so I don't think it's a problem in substance. But I'd drop the Akka PR/commit from the description and references and present it on the scheduler-catch-up analysis alone.
- reference.conf comment. "Delayed timer execution is not compensated with a burst of keepalive ticks" describes an implementation detail that users can't act on. If anything, the useful thing to say is that the interval and timeout are approximate and may be longer under load. Otherwise I'd leave the config docs as they were.
Motivation: The keepalive settings note described a scheduling detail rather than what users can expect from the configured timing. Modification: Explain for both the client and server that the ping interval and acknowledgment timeout are approximate and may be longer under load. Result: The notes describe the observable timing. Configuration defaults, protocol behavior, tests and attribution are unchanged. Tests: Not run - comment-only. git diff --check and exact comment-only diff verification passed. References: Refs apache#1462 and PJ's review.
Motivation: Fixed-rate keepalive ticks can catch up after a scheduler pause and prematurely exhaust the acknowledgment window of a newly sent ping. Modification: Use fixed-delay ticks and cover delayed execution with a deterministic regression. Clarify that the interval and ping timeout may be longer under load for both client and server settings. Result: Delayed callbacks no longer compress the acknowledgment window; unacknowledged pings still time out. Tests: The earlier identical runtime code passed the new focused regression and six existing ping cases. The documentation follow-up was checked as comment-only; no runtime retest or CI query for this squash. References: Refs apache#1462, apache#714 and akka/akka-http#4182.
20b7776 to
8129747
Compare
Motivation: Fixed-rate keepalive ticks can catch up after a scheduler pause and prematurely exhaust the acknowledgment window of a newly sent ping. Modification: Use fixed-delay ticks and cover delayed execution with a deterministic regression. Clarify that the interval and ping timeout may be longer under load for both client and server settings. Result: Delayed callbacks no longer compress the acknowledgment window; unacknowledged pings still time out. Tests: The earlier identical runtime code passed the new focused regression and six existing ping cases. The documentation follow-up was checked as comment-only; no runtime retest or CI query for this squash. References: Refs apache#1462 and apache#714.
8129747 to
8fef30f
Compare
pjfanning
left a comment
There was a problem hiding this comment.
Thanks for the updates; the Akka reference and the reference.conf wording from my earlier review are addressed. A follow-up on the approach and the tests:
Measuring elapsed time instead of counting ticks. EnabledPingState.pingAckOverdue is pingInFlight && ticksSincePing > 1 (Http2Demux.scala:174), so anything that delivers ticks in a burst still produces a false timeout. Fixed delay removes the scheduler's catch-up burst, but not bursts from the stage side (see the inline comment). Recording System.nanoTime() in sendingPing() and checking now - pingSentAt > pingTimeout in the tick handler would make the result independent of how ticks are delivered, while keeping the cheap periodic tick rather than reading the clock per frame. Would you consider that instead of, or as well as, the scheduling change?
PR description. There's no Tests section (the validation notes are under Result), and References should use Refs #... / Fixes #... / None - <context> per AGENTS.md.
|
Correction to point 1 of my earlier review: I was wrong about akka/akka-http#4182. BSL-licensed Akka code becomes Apache 2.0 three years after the first release that contains it. That change first shipped in Akka HTTP 10.5.0 (2023-02-21), so it has been Apache-licensed since 2026-02-21. Citing it is fine, and you're welcome to restore the reference in the description. Sorry for the noise. |
8fef30f to
a826191
Compare
Motivation: HTTP/2 keepalive callbacks may accumulate while either the scheduler or stream interpreter is delayed. Counting callbacks can prematurely expire a newly sent ping even when its acknowledgment budget has not elapsed. Modification: - Keep fixed-delay scheduling and measure outstanding ping age with a monotonic clock. - Keep one ping outstanding so queued ticks cannot replace its send timestamp. - Preserve idle-data accounting, the zero-timeout fallback, and the existing internal two-argument constructor. - Add deterministic clock coverage for queued callbacks, deadline expiry, acknowledgments, ordinary data, and clock wraparound. Pair the delayed-ACK integration with an unacknowledged-ping timeout observation, assert the timeout reason, and drain pending scheduler work in both tests. Result: A callback burst alone cannot consume the acknowledgment budget. Missing acknowledgments still expire after elapsed time, with detection on a subsequent tick. This does not promise immediate processing during dispatcher starvation. Tests: - Offline Scala 2.13.18 compilation of changed production and focused test/support sources with `-deprecation -Wunused:imports -Werror`: passed. - `org.scalatest.tools.Runner -o -s org.apache.pekko.http.impl.engine.http2.Http2PingSchedulingSpec`: 4 passed against cached HTTP module classes/dependencies after rebasing to 73c1ef8, including the exact GOAWAY debug text. - Directional burst test: failed with old runtime body plus constructor-only test shim, passed with the new implementation. - Cached official scalafmt 3.11.5 and `git diff --check`: passed. - Not run: clean sbt build, cross-Scala/MiMa, full client/server ping suites. The no-ACK integration uses a bounded 1200ms no-output observation before advancing the paused scheduler; state-level clock coverage is deterministic. References: Refs apache#714. Related timer discussion: akka/akka-http#4182 (citation only; no source copied for this follow-up). Provenance: preserves original He-Pin PR head 8fef30f and incorporates PJ review feedback.
a826191 to
48a1d19
Compare
pjfanning
left a comment
There was a problem hiding this comment.
LGTM. Note for the release notes: an unacknowledged ping now times out after the elapsed tick interval (1 to 2 ticks), rather than after a fixed 2 ticks.
Motivation: Several recently merged PRs left review points unaddressed: docs that were asked to be dropped, comments and tests that were suggested, and small API and internal tidy-ups. Modification: - Add a Scala FilenameEncoding alias and values to Multipart.FormData and use them in the Scala toEntity signature and tests (#1494). - Render the form-data Content-Disposition header directly instead of rendering it twice and slicing off the prefix (#1494). - Drop the docs paragraph about unpaired URI surrogates (#1426) and the cookie -0000 sentence in request-level.md (#1493). - Fix the javadsl Multipart.FormData doc the same way #1483 fixed the scaladsl one. - Comment the cookie date rule copies so they stay in sync (#1458). - Test custom methods starting with Q next to the QUERY fast path (#1477). - Use one root package import and a dilated timeout in HeaderCompressionSpec (#1438). - Pass isTrailer to HttpMessageRendering.renderHeaders explicitly (#1463). - Remove the unused forwarding overloads in Handshake.Client and EnabledPingState (#1436, #1462). - Move the media type model checks from the routing spec to a new http-core MediaTypesSpec (#1437, #1454). - Hash the WebSocket key without String.valueOf (#1439). Result: The review points are addressed. The only public API change is the added Scala FilenameEncoding alias. Tests: - http-core/testOnly MultipartSpec MultipartsSpec MediaTypesSpec RequestParserCRLFSpec RequestParserLFSpec HeaderCompressionSpec WebSocketClientSpec HeaderSpec HttpHeaderSpec: 314 passed - http2-tests/testOnly HttpMessageRenderingSpec Http2PingSchedulingSpec: 38 passed - http-tests/testOnly FileAndResourceDirectivesSpec: 63 passed - http-core/mimaReportBinaryIssues: passed References: Refs #1426, #1436, #1437, #1438, #1439, #1454, #1458, #1462, #1463, #1477, #1483, #1493, #1494
Motivation
HTTP/2 keepalive callbacks may accumulate while the scheduler or stream interpreter is delayed. Counting callbacks can expire a newly sent ping before its acknowledgment budget has elapsed.
Modification
Keep fixed-delay scheduling and measure elapsed time from the PING send using a monotonic clock. Keep only one ping outstanding so queued ticks cannot replace its timestamp. Preserve idle-data accounting, the zero-timeout fallback and the existing internal two-argument constructor. Add deterministic clock coverage and paired delayed-ACK and no-ACK integration cases.
Result
Callback bursts alone cannot consume the acknowledgment budget. Missing acknowledgments still expire after elapsed time, detected on a subsequent tick. This does not promise immediate processing during dispatcher starvation or exact wall-clock timeout precision.
Release note
HTTP/2 keepalive: an unacknowledged ping now times out based on elapsed time since it was sent, measured against the tick interval (
ping-timeout, orping-intervalwhenping-timeoutis 0). The timeout is detected on the next tick, so the connection is closed after 1 to 2 tick intervals. Before, it always took 2 ticks, so the effective timeout may be shorter than in previous versions. Timer callbacks that queue up while the connection's stage is delayed no longer cause false ping timeouts.Tests
GitHub CI passed on this exact revision, including Validate and test run 44233089324.
References
Refs #714.
Related timer discussion: akka/akka-http #4182, retained as a citation following PJ's clarification. No source was copied for this follow-up.
Original production copyright notices are retained; independently written tests have ASF headers.