-
Notifications
You must be signed in to change notification settings - Fork 19
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
[sdk#1026] Use postpone.ContextWithValues() #248
Conversation
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() |
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.
@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 ?
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.
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
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.
oh! ok, interesting change. is i.Close
invoked with closeCtx which has extended deadline ?
should cancelClose()
be called at the end ?
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.
Yes closeCtx
has postponed deadline in comparison with ctx
.
cancelClose()
is called with defer, so closeCtx
would be gracefully closed.
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.
ah! yes, correct. with this closeCtx's Done channel closed gracefully only after executing new hop's close handlers.
…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>
…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>
…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>
…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>
Description
Use
postpone.ContextWithValues()
forClose
/Unregister
in failedRequest
/Register
cases.Depends on networkservicemesh/sdk#1035.Issue link
networkservicemesh/sdk#1026
How Has This Been Tested?
Types of changes