konlue opened a new pull request, #7939:
URL: https://github.com/apache/shenyu/pull/7939
Fixes #7918.
## Summary
Two connections with the same `clientId` could coexist: `Connect` only
mapped channel→`clientId`, so a second CONNECT with the same id was accepted
while the first channel stayed open. Worse, when the *old* channel later
disconnected, `cleanChannel` resolved the `clientId` and unconditionally
discarded the session — deleting the live session of the connection that
replaced it.
## Modifications
- `ChannelRepository` now keeps a `clientId`→channel ownership index. `add`
registers ownership; `takeover` atomically transfers it and returns the
previously owning channel.
- `Connect` takes over the id: when a different channel already owns it, its
stored will is discarded (the client is alive on the new connection) and the
previous connection is closed, per MQTT-3.1.4.
- `cleanChannel` fences the session-scoped cleanup on ownership: a replaced
connection closing late can no longer discard the session of its replacement.
Channel-scoped cleanup (subscriptions, channel mapping, outbound packet ids) is
unchanged — it only touches the dead channel's own entries.
## Verifying this change
- [x] `testTakeoverClosesThePreviousChannel`: the second connect is accepted
and the first channel is closed. Fails on the previous code (both channels
stayed open).
- [x] `testStaleChannelCleanupKeepsTheNewSession` (the issue's repro): after
the takeover, running the stale channel's cleanup leaves the session intact.
Fails on the previous code (session deleted).
- [x] `testWillOfReplacedConnectionIsDiscarded`: the will of the replaced
connection is dropped and never fires.
- [x] Full module tests and Checkstyle pass:
```bash
./mvnw -pl shenyu-protocol/shenyu-protocol-mqtt checkstyle:check
```
132/132 green (Connect / Disconnect / session-present regressions
included); checkstyle clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]