apache / apache/shenyu

[BUG] Inbound MqttPublishMessage payload ByteBuf never released; async fan-out shares it unsafely

Open
#6,639 2 comments 0 reactions 1 assignee Claimed by @wy471x View on GitHub
plugin: mqtt priority: high type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- severity: High
- files: `shenyu-protocol/shenyu-protocol-mqtt/src/main/java/org/apache/shenyu/protocol/mqtt/MqttTransportHandler.java:32-39`; `Publish.java:46-57,115-126`
- description: `MqttTransportHandler extends ChannelInboundHandlerAdapter` (not `SimpleChannelInboundHandler`), so inbound messages are not auto-released, and the handler never calls `ReferenceCountUtil.release(msg)`. The `MqttPublishMessage` payload ByteBuf is leaked on every PUBLISH. Additionally `CompletableFuture.runAsync(() -> send(topic, payload, packetId))` hands the same payload ByteBuf to `Unpooled.wrappedBuffer(payload)` for every subscriber channel in parallel with no per-write retain.
- impact: Native/pooled buffer leak per PUBLISH; potential `IllegalReferenceCountException` or buffer corruption under multi-subscriber fan-out.
- suggested_fix: Release inbound message in `channelRead` (or extend `SimpleChannelInboundHandler`); `payload.retainedDuplicate()` per subscriber write.
- confidence: High
- related_existing: none

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.