Skip to content

fix: align inbound and outbound packet size checks and drop oversize messages (#313) - #314

Open
abhiramaab wants to merge 1 commit into
apache:mainfrom
abhiramaab:fix/issue-313-packet-size-alignment
Open

abhiramaab wants to merge 1 commit into
apache:mainfrom
abhiramaab:fix/issue-313-packet-size-alignment

Conversation

@abhiramaab

Copy link
Copy Markdown

Purpose

Resolves #313 by aligning inbound Netty decoder limits with MQTT variable-length integer framing and adding outbound packet-size enforcement in MQTTSessionHandler.

Changes

  1. Varint-Aware Inbound Limit (ChannelAttrs.java)

    • Accurately calculates maxRemainingLength(maxPacketSize) by accounting for the fixed header byte and the variable-length integer overhead.
    • Handles the 1–4 byte variable-length integer based on the remaining-length threshold instead of performing a raw subtraction.
  2. Outbound Packet Size Enforcement (MQTTSessionHandler.java)

    • Enforces the client-negotiated/tenant maxPacketSize in publishConfirmable().
    • Drops packets that exceed the maximum size with DropReason.ResourceExhausted.
    • Emits OversizePacketDropped protocol events for dropped packets.
    • Confirms the message promise cleanly to prevent resource leaks.
  3. Protocol Helper Support (IMQTTProtocolHelper.java)

    • Implements maxPacketSize() in both MQTT3ProtocolHelper and MQTT5ProtocolHelper.
    • Respects the MQTT 5 Maximum Packet Size connection property while applying the tenant-level limit.
  4. Unit Tests (ChannelAttrsTest.java)

    • Added exhaustive boundary tests covering exact-fit and variable-length integer crossover points:
      • 127 / 128
      • 16,383 / 16,384
      • 2,097,151 / 2,097,152

Verification

  • ChannelAttrsTest: Passed (2/2)
  • TransientSessionHandlerTest & PersistentSessionHandlerTest: Passed (74/74)
  • Checkstyle: 0 violations

Copilot AI balanced review requested due to automatic review settings October 3, 2026 14:45

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants