Skip to content
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

Fix chain elements init function #506

Merged

Conversation

glazychev-art
Copy link
Contributor

Closes: networkservicemesh/deployments-k8s#2800

Motivation

If context was canceled (e.g by timeout) in the middle of the chain, and the next chain element has init function with sync.Once - we have no chance to call init again. We store the error and all new Requests will fail with that error.

Solution

Call the init function only the first time, OR if the first call returned an error.

Signed-off-by: Artem Glazychev [email protected]

u.initErr = initFunc(ctx, u.vppConn)
})
return u.initErr
if !u.inited.Load() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks not thread-safe. A few goroutines could read u.inited as a false and block on the u.initMutex.

Copy link
Member

@denis-tingaikin denis-tingaikin Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we could add something like this https://go.dev/play/p/f2J7aioP59W and add this into sdk/tools as a common solution for chain elements with init functions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edwarnicke Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, we also could use a personal Executor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denis-tingaikin
I like the idea about extended sync.Once and add it to sdk/tools.
Prepared PR: networkservicemesh/sdk#1224

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it inline

go.mod Outdated Show resolved Hide resolved
Signed-off-by: Artem Glazychev <[email protected]>
@denis-tingaikin
Copy link
Member

This problem is actual. So merging.

@edwarnicke Please have a look at networkservicemesh/sdk#1224 this can a bit simplify these changes.

@denis-tingaikin denis-tingaikin merged commit 807bc2b into networkservicemesh:main Feb 4, 2022
nsmbot pushed a commit to networkservicemesh/cmd-nsc-vpp that referenced this pull request Feb 4, 2022
…k-vpp@main

PR link: networkservicemesh/sdk-vpp#506

Commit: 807bc2b
Author: Artem Glazychev
Date: 2022-02-04 17:12:04 +0700
Message:
  - Fix chain elements init function (#506)
Signed-off-by: NSMBot <[email protected]>
nsmbot pushed a commit to networkservicemesh/cmd-forwarder-vpp that referenced this pull request Feb 4, 2022
…k-vpp@main

PR link: networkservicemesh/sdk-vpp#506

Commit: 807bc2b
Author: Artem Glazychev
Date: 2022-02-04 17:12:04 +0700
Message:
  - Fix chain elements init function (#506)
Signed-off-by: NSMBot <[email protected]>
nsmbot pushed a commit to networkservicemesh/cmd-nse-icmp-responder-vpp that referenced this pull request Feb 4, 2022
…k-vpp@main

PR link: networkservicemesh/sdk-vpp#506

Commit: 807bc2b
Author: Artem Glazychev
Date: 2022-02-04 17:12:04 +0700
Message:
  - Fix chain elements init function (#506)
Signed-off-by: NSMBot <[email protected]>
nsmbot pushed a commit to networkservicemesh/cmd-nse-firewall-vpp that referenced this pull request Feb 4, 2022
…k-vpp@main

PR link: networkservicemesh/sdk-vpp#506

Commit: 807bc2b
Author: Artem Glazychev
Date: 2022-02-04 17:12:04 +0700
Message:
  - Fix chain elements init function (#506)
Signed-off-by: NSMBot <[email protected]>
nsmbot pushed a commit to networkservicemesh/cmd-nse-vlan-vpp that referenced this pull request Feb 4, 2022
…k-vpp@main

PR link: networkservicemesh/sdk-vpp#506

Commit: 807bc2b
Author: Artem Glazychev
Date: 2022-02-04 17:12:04 +0700
Message:
  - Fix chain elements init function (#506)
Signed-off-by: NSMBot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestRemote_nsmgr_restart/TestRunHealSuite is unstable on GKE
2 participants