Skip to content

fix: account for HTTP/2 DATA discarded after stream closure - #1668

Draft
He-Pin wants to merge 2 commits into
apache:mainfrom
He-Pin:fix/http2-closed-stream-data-receive-credit
Draft

He-Pin wants to merge 2 commits into
apache:mainfrom
He-Pin:fix/http2-closed-stream-data-receive-credit

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Motivation

When HTTP/2 discards DATA after a stream has closed, those bytes still count toward the connection's receive window.

Modification

Count the complete DATA payload once in the existing closed-stream handling path. Apply the normal connection-level credit update policy without retaining entity bytes, granting stream-level credit, or reopening the stream.

Result

Discarded DATA is accounted for at the connection level without changing entity delivery or stream-level flow control.

Tests

On JDK 17, 14 focused tests passed on each of Scala 2.13.18 and 3.3.9. MiMa passed. Full CI was not run locally.

References

Dependency

Stacked on apache/pekko-http#1666. Since this upstream draft targets main, GitHub's full diff includes the dependency until it merges. Review the follow-up commit only. This draft will be rebased on main after #1666 merges and should not merge before then.

Motivation
HTTP/2 flow control counts the full received DATA payload, while the entity exposes only its content.

Modification
Carry padding overhead separately from application bytes. Apply window accounting before and after request entity dispatch without charging buffered bytes twice. Reuse the existing batching policy for discarded padding.

Result
Receive windows reflect the DATA payload while entity bytes and Content-Length remain unchanged.

References
RFC 9113 sections 6.1 and 6.9.1.
Motivation
HTTP/2 DATA received for a closed stream can still consume the
connection-level receive window even when the stream discards it.

Modification
Debit the full flow-controlled size without retaining entity bytes or
updating the closed stream. Keep other streams' buffered bytes reserved
and replenish connection credit through the existing batching policy.
Use the existing connection-error path when credit is insufficient.
Check the connection-only credit in the existing cancellation test
before checking that a subsequent exchange still succeeds.

Result
Discarding DATA no longer leaves the connection's receive accounting
out of sync with the peer. The stream remains closed.

References
RFC 9113 sections 5.1, 6.4 and 6.9.
@He-Pin
He-Pin force-pushed the fix/http2-closed-stream-data-receive-credit branch from fe4813e to 77dbbe8 Compare November 26, 2026 17:11
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.

1 participant