Aias00 opened a new issue, #7315: URL: https://github.com/apache/shenyu/issues/7315
## Current Behavior `WebsocketCollector#clearSession` removes a session from the global set and send-queue map, then calls `getNamespaceId(session)` before removing it from `NAMESPACE_SESSION_MAP`. However, `getNamespaceId` immediately returns `null` when `session.isOpen()` is false. `clearSession` is called by `@OnClose` and `@OnError`, where the session is commonly already closed. The namespace removal is therefore skipped and the closed session remains in the namespace set. Later namespace broadcasts iterate the stale session. They may recreate a `SessionSendQueue`, produce repeated send failures, retain session objects, and increase work after every reconnect. A related lifecycle problem exists in `onOpen`: the session is added to the global set before namespace validation, so a missing namespace can leave partially registered state when an exception is thrown. ## Reproduction - Open/register a session for a namespace. - Mark the mocked session closed and invoke `onClose` or `onError`. - Verify the current session remains in `NAMESPACE_SESSION_MAP`. - Reconnect repeatedly and verify the namespace set grows with closed sessions. - Broadcast a namespace update and verify closed sessions are still traversed. ## Expected Behavior Session registration and removal must be atomic and complete, regardless of whether the underlying session is already closed. ## Scope - Persist the namespace associated with each registered session independently of `Session.isOpen()`, or read it before teardown. - Remove sessions from global, namespace, and send-queue indexes in one idempotent cleanup path. - Remove empty namespace sets. - Validate namespace before publishing the session into any collection. - Make repeated `onClose`/`onError` calls harmless. - Add session-count and stale-session metrics by namespace. ## Acceptance Criteria - [ ] Closed/error sessions are removed from every collection and queue map. - [ ] Missing-namespace handshakes leave no partial registration. - [ ] Repeated reconnects do not grow namespace session sets. - [ ] Namespace broadcasts target only open, fully registered sessions. - [ ] Cleanup is idempotent under close/error/send-failure races. - [ ] Unit tests cover already-closed sessions, missing namespace, repeated cleanup, and reconnect loops. -- 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]
