Repository navigation
fix(websockets): resolve global scoped enhancers per connection - #17979
Merged
kamilmysliwiec merged 3 commits intoOct 2, 2026
Merged
Conversation
# Conflicts: # packages/websockets/test/web-sockets-controller.spec.ts # packages/websockets/web-sockets-controller.ts
This was referenced Oct 6, 2026
This was referenced Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
A request-scoped or transient
APP_GUARDis skipped on singleton WebSocket gateways, so even a guard that returnsfalseallows the message handler to run. On gateways with a request-scoped dependency tree, global scoped enhancers can be read before their constructors and injected dependencies have been initialized. Global scoped pipes and interceptors are affected as well.Closes #17975.
What is the new behavior?
WebSocket message handlers resolve global scoped guards, pipes and interceptors in the existing socket connection context before building the execution pipeline. Singleton gateways remain singletons, preserving their constructor initialization, shared state,
afterInitandonModuleInitbehavior.The injector accepts an explicit enhancer list, allowing these globals to be loaded without adding them to the gateway dependency tree. Local transient enhancers are also loaded when a singleton message pipeline uses a connection context. Disconnect cleanup releases the connection context after the singleton gateway's async hook completes, including gateways without a disconnect hook. Global exception filters retain their existing exclusion from WebSocket pipelines.
Regression coverage includes denying guards on singleton and request-scoped gateways, REQUEST and TRANSIENT enhancer construction and injection, reuse within a connection and isolation across connections, pipe/interceptor-only registrations, singleton lifecycle/state, disconnect cleanup, and mixing global scoped with local transient enhancers.
Does this PR introduce a breaking change?
Other information
Validation on Windows with Node.js 24.15.0:
npm run buildβ passed.npm run lintβ passed, with one existing warning insocket-module.ts.git diff --checkβ passed.The unmodified unit-test command hit an existing color assertion because this environment sets
NO_COLOR=1, and its SIGTERM tests terminated the worker on Windows. The successful unit run clearedNO_COLORand used:The full Docker-dependent integration suite was not run.