-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add the possible to make chain of chains via pkg/next #173
Add the possible to make chain of chains via pkg/next #173
Conversation
Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
91f00de
to
51e26ef
Compare
I'm not following the problem we are trying to solve here... could you say more? It's unclear to me why the existing code does not allow you to use one chain as an element in another. |
Sure, we are trying to use chains inside chains. For example: next.NewServer(next.NetServer(somepkg.NewServer()), somepkg.NewServer())
The problem related to two things:
|
Oh... that is nicely subtle. Good catch. Question thought... might it not be simpler and clearer to simply do something like replacing return n.servers[n.index].Request(withNextServer(ctx, nil), request) with return n.servers[n.index].Request(ctx, request) That way any 'nextServer' coming from the parent would show up for the child? |
Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
@edwarnicke good idea. Thanks, fixed. |
@@ -48,6 +48,9 @@ func withNextServer(parent context.Context, next networkservice.NetworkServiceSe | |||
// Server - | |||
// Returns the Server networkservice.NetworkServiceServer to be called in the chain from the context.Context | |||
func Server(ctx context.Context) networkservice.NetworkServiceServer { | |||
if ctx == nil { |
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.
Question... why return nil here instead of tailServer?
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.
actually it can be nil in two cases:
- At the first call of method request/close with
ctx = nil
. In this case, we looking for the next parent chain and value can benil
- Call this method outside of the chain. I.e. user not used
next.NewServer()
and passednil
context. Not sure that we should returntailServer
in this case
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.
Finally, I think it will be better just throw nil panic exception for the case №2.
Fixed by 1d5588c
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.
Why would we panic if called outside of a chain?
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.
Why would we panic if called outside of a chain?
I think ignoring errors is not a good pattern for this place.
- We already use similar behavior:
1.1 https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/core/trace/context.go#L43
1.2. https://github.com/networkservicemesh/sdk-vppagent/blob/master/pkg/networkservice/vppagent/context.go#L50
1.3. https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/clienturl/context.go#L44
1.4. https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/discover/context.go#L46
1.5. https://github.com/networkservicemesh/sdk/blob/master/pkg/registry/core/trace/context.go#L43
... - I think if the user tries to use nil context to get the value then it is an invalid case. And we should not ignore the invalid state.
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.
That's fair :)
Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
…i@main PR link: networkservicemesh/api#173 Commit: f357d8c Author: Nikita Skrynnik Date: 2024-04-12 00:04:02 +0700 Message: - Remove some triggers from Update dependent repositories (#173) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…i@main (#1611) PR link: networkservicemesh/api#173 Commit: f357d8c Author: Nikita Skrynnik Date: 2024-04-12 00:04:02 +0700 Message: - Remove some triggers from Update dependent repositories (#173) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
Signed-off-by: denis-tingajkin denis.tingajkin@xored.com
Motivation
#172