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

[sdk#1026] Use postpone.ContextWithValues() #248

Merged

Conversation

Bolodya1997
Copy link

Description

Use postpone.ContextWithValues() for Close/Unregister in failed Request/Register cases.

Depends on networkservicemesh/sdk#1035.

Issue link

networkservicemesh/sdk#1026

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionallity
  • Documentation
  • Refactoring
  • CI

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
if _, closeErr := next.Client(ctx).Close(ctx, conn, opts...); closeErr != nil {
logger.Errorf("failed to close failed connection: %s %s", conn.GetId(), closeErr.Error())
closeCtx, cancelClose := postponeCtxFunc()
defer cancelClose()
Copy link
Member

Choose a reason for hiding this comment

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

@Bolodya1997 I'm not sure if I fully understand this solution, are you trying to postpone the invocation of i.Close with closeCtx ? what is the purpose of this ?

Copy link
Author

Choose a reason for hiding this comment

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

We have met an issue in our integration tests - networkservicemesh/sdk#1026.
In short - sometimes Request context can be expired/canceled and so Close on failure cannot reach next hop.
So here it is actually a pattern we are planning to use to solve this issue.

// 1. Capture ctx values and timeout before the Request.
postponeCtxFunc := postpone.ContextWithValues(ctx)

// 2. Perform Request.
conn, err = next.Client(ctx).Request(ctx, request)
if err != nil {
    return nil, err
}

if err := doSomething(); err != nil {
    // 3. Create Close context using stored timeout, values.
    closeCtx, cancelClose := postponeCtxFunc()
    defer cancelClose()

    // 4. Perform Close using Close context.
    if _, closeErr := i.Close(closeCtx, conn, opts...); closeErr != nil {
        err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error())
    }
    return nil, err
}

return conn, nil

Copy link
Member

Choose a reason for hiding this comment

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

oh! ok, interesting change. is i.Close invoked with closeCtx which has extended deadline ?
should cancelClose() be called at the end ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes closeCtx has postponed deadline in comparison with ctx.
cancelClose() is called with defer, so closeCtx would be gracefully closed.

Copy link
Member

Choose a reason for hiding this comment

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

ah! yes, correct. with this closeCtx's Done channel closed gracefully only after executing new hop's close handlers.

@denis-tingaikin denis-tingaikin merged commit cfe1b24 into networkservicemesh:main Aug 24, 2021
nsmbot pushed a commit to networkservicemesh/cmd-nsc that referenced this pull request Aug 24, 2021
…k-sriov@main

PR link: networkservicemesh/sdk-sriov#248

Commit: cfe1b24
Author: Denis Tingaikin
Date: 2021-08-24 13:36:00 +0300
Message:
  - Merge pull request #248 from Bolodya1997/sdk#1026/postpone
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsc-init that referenced this pull request Aug 24, 2021
…k-sriov@main

PR link: networkservicemesh/sdk-sriov#248

Commit: cfe1b24
Author: Denis Tingaikin
Date: 2021-08-24 13:36:00 +0300
Message:
  - Merge pull request #248 from Bolodya1997/sdk#1026/postpone
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-forwarder-sriov that referenced this pull request Aug 24, 2021
…k-sriov@main

PR link: networkservicemesh/sdk-sriov#248

Commit: cfe1b24
Author: Denis Tingaikin
Date: 2021-08-24 13:36:00 +0300
Message:
  - Merge pull request #248 from Bolodya1997/sdk#1026/postpone
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-ovs that referenced this pull request Aug 24, 2021
…k-sriov@main

PR link: networkservicemesh/sdk-sriov#248

Commit: cfe1b24
Author: Denis Tingaikin
Date: 2021-08-24 13:36:00 +0300
Message:
  - Merge pull request #248 from Bolodya1997/sdk#1026/postpone
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
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.

4 participants