-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create method on client to get websocket pattern #10545
feat: create method on client to get websocket pattern #10545
Conversation
Pull Request Test Coverage Report for Build 687f5680-c7ea-440a-8484-35693509459c
💛 - Coveralls |
ExecutionContext#switchToWs().getClient<Socket>() ? |
We could update the generic of |
Object.assign(args[0] ?? {}, { | ||
getPattern: () => this.reflectCallbackPattern(callback), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.assign(args[0] ?? {}, { | |
getPattern: () => this.reflectCallbackPattern(callback), | |
}); | |
Object.assign(args[0] ?? {}, { | |
getPattern: () => this.reflectCallbackPattern(callback), | |
}); |
Hmm.. I'm wondering if this won't cause some unexpected issues 🤔 If socket represents a single connection (and so its instance object is shared?), there's a probability that 2 messages from that socket might be processed asynchronously (independently).
Example:
- Connection to server is established (socket instance is created)
- Message A is emitted
- we mutate the "socket instance" enhancing it with the "getPattern()" method
- before this message is processed, some asynchronous operation is triggered in (guard/interceptor/wherever)
- In the meantime, message B is emitted
- we mutate the same "socket instance" again replacing the previous "getPattern()" method
- Async operation (mentioned above) completes and we're back to processing message A.
- In another interceptor/guard we call
client.getPattern()
when processing message A but it's already overridden with the message B's "getPattern" implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than mutating the client, could I add a new args
entry and let getPattern()
retrieve args[2]
? Would that be more "stable"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great call by the way! I moved getPattern
to be a method on WsArgumentHost
instead of under the getClient()
so that it should be unique per request as the WsArgumentHost
already is. Tests are still passing and the interfaces are updated. Let me know if you think of any other issues with this approach 😸
691049c
to
4a10b88
Compare
.circleci/config.yml
Outdated
@@ -35,7 +35,7 @@ jobs: | |||
- checkout | |||
- run: | |||
name: Update NPM version | |||
command: 'sudo npm install -g npm@latest' | |||
command: 'sudo npm install -g npm@^8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm v9 was released on 2022-10-24 is is not compatible with node 12. Today (2022-11-09) it was set to the @latest
tag for npm
so our CircleCI builds started breaking.
Wednesday Nov. 9th (General Availability)
To ensure npm@9.x is considered "non-breaking" for Node.js LTS we will codify a set of exit criteria in collaboration with the Release WG
npm@9.x will be set to the latest dist-tag (becoming the latest, maintained version of npm)
A PR will be opened to land npm@9.x in nodejs/node's main branch (exposing experimental/nightly users to this latest version)
https://github.blog/changelog/2022-10-24-npm-v9-0-0-released/
Hey @kamilmysliwiec anything else you'd like me to work with on this feature? |
76b2196
to
ff9a577
Compare
Hey @kamilmysliwiec any chance this can make it in before v10? |
@kamilmysliwiec just making sure there's visibility on this. I know you've got your hands full with a lot. I'd like to get this merged in so I can make a minor release with a new feature for ogma before I release a major upgrade with breaking changes, as this would be a super helpful feature when it comes to logging errors |
LGTM |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The only way to get the websocket pattern is through reflection, which is unavailable inside of filters as the
ArgumentsHost
doesn't have agetClass
orgetHandler
method.Issue Number: #10520
What is the new behavior?
ExecutionContext#switchToWs().getClient()
now has agetPattern()
method attached to it so that the pattern can be retrieved in filters.This pattern is still a reflected pattern, and not retrieved from the direct request, as we don't, to my knowledge, bind the exception filter for when invalid patterns are called (if I'm wrong about that please point to where it is)
Does this PR introduce a breaking change?
Other information