Skip to content

fix(websocket): derive the inflate limit from the retained decompressed data - #17

Merged
terry-xiaoyu merged 1 commit into
emqx-2.13.xfrom
261009-ws-deflate-budget
Oct 12, 2026
Merged

terry-xiaoyu merged 1 commit into
emqx-2.13.xfrom
261009-ws-deflate-budget

Conversation

@terry-xiaoyu

@terry-xiaoyu terry-xiaoyu commented Oct 9, 2026 •

Copy link
Copy Markdown

Ports the upstream accounting fix (ninenines/cowboy 09d0a24b14) to the 2.13 line EMQX pins, and applies it to the cowboy_websocket_linger module this fork adds.

What changed

  • The remaining inflate budget now comes from the decompressed payload retained for the current message.
  • The masking offset continues to use the wire byte counter.
  • The ps_payload field holding the decompressed payload is renamed to payload. Field count and order are unchanged, so a suspended connection can carry its parse state across a code upgrade.

Tests

test/ws_SUITE.erl gains a serial group per websocket module covering compressed messages delivered in several TCP segments: over the limit, exactly at the limit, with a non-zero masking key, fragmented messages, and max_frame_size = infinity. Segment delivery is made deterministic by waiting for the connection's inflate result, responses are read by frame length, and meck is added as a test dependency for the barrier.

Local runs on OTP 27: ws_SUITE 110/110 and ws_handler_SUITE 106/106.

Upstream

The same accounting fix is in upstream master as 09d0a24b14. This branch keeps the 2.13 structure: a separate cowboy_websocket_linger module and infinity as the default limit.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The upstream fix is consistently applied and covered across both WebSocket implementations.

0 open findings

What changed in this PR

Ports the upstream WebSocket inflate-budget fix to both WebSocket implementations.

Changes:

  • Derives remaining inflate capacity from retained decompressed payload.
  • Adds segmented, masked, fragmented, boundary, and unlimited-size tests.
  • Adds meck for deterministic inflate barriers.
File Description
src/​cowboy_websocket.erl Corrects inflate-limit accounting.
src/​cowboy_websocket_linger.erl Mirrors the accounting fix.
test/​ws_SUITE.erl Adds comprehensive regression coverage.
test/​ws_SUITE_data/​ws_max_frame_size_deflate.erl Provides the limit-aware echo handler.
Makefile Adds the meck test dependency.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ed data

The remaining inflation budget now comes from the decompressed payload
retained for the current message.

The masking offset continues to use the wire byte counter. The ps_payload
field holding the decompressed payload is renamed to payload; field count
and order are unchanged.

The tests cover compressed messages delivered in several TCP segments:
over the limit, exactly at the limit, a non-zero masking key, fragmented
messages and max_frame_size = infinity. Responses are read by frame
length, so a frame split over several receives is handled.
@terry-xiaoyu
terry-xiaoyu force-pushed the 261009-ws-deflate-budget branch from 0cabc74 to c26e97f Compare October 9, 2026 20:04
@terry-xiaoyu terry-xiaoyu self-assigned this Oct 10, 2026
@terry-xiaoyu
terry-xiaoyu merged commit 0d68e81 into emqx-2.13.x Oct 12, 2026
4 checks passed
@terry-xiaoyu
terry-xiaoyu deleted the 261009-ws-deflate-budget branch October 12, 2026 02:31
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.

3 participants