forked from edwarnicke/vpphelper
-
Notifications
You must be signed in to change notification settings - Fork 6
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 monitoring for original context in extendedConnection
struct
#10
Merged
denis-tingaikin
merged 3 commits into
networkservicemesh:main
from
NikitaSkrynnik:extended
Dec 6, 2024
Merged
Add monitoring for original context in extendedConnection
struct
#10
denis-tingaikin
merged 3 commits into
networkservicemesh:main
from
NikitaSkrynnik:extended
Dec 6, 2024
Conversation
This file contains 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
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
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.
I think we can simplify it. Thoughts?
diff --git a/extendtimeout/connection.go b/extendtimeout/connection.go
index 288a872..e34a6f4 100644
--- a/extendtimeout/connection.go
+++ b/extendtimeout/connection.go
@@ -21,7 +21,6 @@ import (
"context"
"time"
- "github.com/edwarnicke/log"
"go.fd.io/govpp/api"
)
@@ -48,27 +47,26 @@ func NewConnection(vppConn api.Connection, contextTimeout time.Duration) api.Con
}
func (c *extendedConnection) Invoke(ctx context.Context, req, reply api.Message) error {
- ctx, cancel := c.withExtendedTimeoutCtx(ctx)
+ ctx, cancel := c.withExtenedTimeoutContext(ctx)
err := c.Connection.Invoke(ctx, req, reply)
cancel()
return err
}
-func (c *extendedConnection) withExtendedTimeoutCtx(ctx context.Context) (extendedCtx context.Context, cancel func()) {
- deadline, ok := ctx.Deadline()
- if !ok {
- return ctx, func() {}
- }
+func(c *extendedConnection) withExtenedTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc) {
+ var cancelContext, cancel = context.WithCancel(context.Background())
+ var timeoutContext, timeoutCancel = context.WithTimeout(cancelContext, c.contextTimeout)
+ go func() {
+ <-timeoutContext.Done()
+ timeoutCancel()
+ select {
+ case <-cancelContext.Done():
+ return
+ case <-ctx.Done():
+ cancel()
+ return
+ }
+ }()
- minDeadline := time.Now().Add(c.contextTimeout)
- if minDeadline.Before(deadline) {
- return ctx, func() {}
- }
- log.Entry(ctx).Warnf("Context deadline has been extended by extendtimeout from %v to %v", deadline, minDeadline)
- deadline = minDeadline
- postponedCtx, cancel := context.WithDeadline(context.Background(), deadline)
- return &extendedContext{
- Context: postponedCtx,
- valuesContext: ctx,
- }, cancel
+ return cancelContext, cancel
}
diff --git a/extendtimeout/connection_test.go b/extendtimeout/connection_test.go
index 4d0025e..7af4f30 100644
--- a/extendtimeout/connection_test.go
+++ b/extendtimeout/connection_test.go
@@ -39,44 +39,6 @@ func (c *testConn) Invoke(ctx context.Context, req, reply api.Message) error {
return nil
}
-type key struct{}
-
-const value = "value"
-
-func TestSmallTimeout(t *testing.T) {
- testConn := &testConn{invokeBody: func(ctx context.Context) {
- deadline, ok := ctx.Deadline()
- require.True(t, ok)
- timeout := time.Until(deadline)
- require.Greater(t, timeout, time.Second)
- require.Equal(t, ctx.Value(&key{}), value)
- }}
-
- smallCtx, cancel := context.WithTimeout(context.Background(), time.Millisecond*10)
- smallCtx = context.WithValue(smallCtx, &key{}, value)
- defer cancel()
-
- err := extendtimeout.NewConnection(testConn, 2*time.Second).Invoke(smallCtx, nil, nil)
- require.NoError(t, err)
-}
-
-func TestBigTimeout(t *testing.T) {
- testConn := &testConn{invokeBody: func(ctx context.Context) {
- deadline, ok := ctx.Deadline()
- require.True(t, ok)
- timeout := time.Until(deadline)
- require.Greater(t, timeout, 7*time.Second)
- require.Equal(t, ctx.Value(&key{}), value)
- }}
-
- bigCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- bigCtx = context.WithValue(bigCtx, &key{}, value)
- defer cancel()
-
- err := extendtimeout.NewConnection(testConn, 2*time.Second).Invoke(bigCtx, nil, nil)
- require.NoError(t, err)
-}
-
func TestNoTimeout(t *testing.T) {
testConn := &testConn{invokeBody: func(ctx context.Context) {
_, ok := ctx.Deadline()
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
denis-tingaikin
approved these changes
Dec 6, 2024
nsmbot
pushed a commit
to networkservicemesh/cmd-nsc-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-forwarder-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-nse-simple-vl3-docker
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-nse-icmp-responder-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-nse-firewall-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-nsc-simple-docker
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-nse-vl3-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/cmd-nse-vlan-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
This was referenced Dec 6, 2024
Merged
nsmbot
added a commit
to networkservicemesh/cmd-nsc-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main (#738) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/deployments-k8s
that referenced
this pull request
Dec 6, 2024
…d-nsc-vpp@main PR link: networkservicemesh/cmd-nsc-vpp#738 Commit: 25125e9 Author: Network Service Mesh Bot Date: 2024-12-06 04:21:23 -0600 Message: - Update go.mod and go.sum to latest version from networkservicemesh/vpphelper@main (#738) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
added a commit
to networkservicemesh/cmd-nse-icmp-responder-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main (#721) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
added a commit
to networkservicemesh/cmd-nse-firewall-vpp
that referenced
this pull request
Dec 6, 2024
…phelper@main (#556) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/deployments-k8s
that referenced
this pull request
Dec 6, 2024
…d-nse-icmp-responder-vpp@main PR link: networkservicemesh/cmd-nse-icmp-responder-vpp#721 Commit: 932b2b0 Author: Network Service Mesh Bot Date: 2024-12-06 04:21:40 -0600 Message: - Update go.mod and go.sum to latest version from networkservicemesh/vpphelper@main (#721) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
pushed a commit
to networkservicemesh/deployments-k8s
that referenced
this pull request
Dec 6, 2024
…d-nse-firewall-vpp@main PR link: networkservicemesh/cmd-nse-firewall-vpp#556 Commit: 4880cdd Author: Network Service Mesh Bot Date: 2024-12-06 04:21:48 -0600 Message: - Update go.mod and go.sum to latest version from networkservicemesh/vpphelper@main (#556) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
added a commit
to networkservicemesh/deployments-k8s
that referenced
this pull request
Dec 6, 2024
…d-nsc-vpp@main (#12584) PR link: networkservicemesh/cmd-nsc-vpp#738 Commit: 25125e9 Author: Network Service Mesh Bot Date: 2024-12-06 04:21:23 -0600 Message: - Update go.mod and go.sum to latest version from networkservicemesh/vpphelper@main (#738) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot
added a commit
to networkservicemesh/deployments-k8s
that referenced
this pull request
Dec 6, 2024
…d-nse-icmp-responder-vpp@main (#12562) PR link: networkservicemesh/cmd-nse-icmp-responder-vpp#721 Commit: 932b2b0 Author: Network Service Mesh Bot Date: 2024-12-06 04:21:40 -0600 Message: - Update go.mod and go.sum to latest version from networkservicemesh/vpphelper@main (#721) PR link: networkservicemesh/vpphelper#10 Commit: 6f75d67 Author: Denis Tingaikin Date: 2024-12-06 05:18:38 -0500 Message: - Merge pull request #10 from NikitaSkrynnik/extended Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
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.
Description
Add monitoring of original context canceling in
extendedConnection
Issue
networkservicemesh/cmd-forwarder-vpp#1133