-
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
Close resources on expired Request context #1026
Comments
Possible solutionWe can introduce some utilities methods (for server and client cases) responsible for Close on failure case. const closeTimeout = time.Duration(...)
func CloseServer(ctx, chainCtx context.Context, conn *networkservice.Connection) {
logger := log.FromContext(ctx).WithField("onfailure", "CloseServer")
var timeout time.Duration
if deadline, ok := ctx.Deadline(); ok {
timeout = time.Until(deadline)
}
if timeout < closeTimeout {
timeout = closeTimeout
}
closeCtx, cancelClose := context.WithTimeout(chainCtx, timeout)
defer cancelClose()
if _, err := next.Server(ctx).Close(closeCtx, conn); err != nil {
logger.Errorf("failed to close connection: %s %s", conn.GetId(), err.Error())
}
} And force everyone to use it instead of simple Close on failure. @edwarnicke @denis-tingaikin |
@Bolodya1997 Good catch. Your proposed solution though would loose the metadata for the connection that is needed to properly clean it things up. Mulling a bit the cleanest way to handle that. Also: we have a repeated pattern of needing a context with a timeout that is in the future... might make sense to solve that problem generically rather than introducing a new CloseServer function... |
Expected Behavior
If chain element first make Request after makes some logic and fails on it, it should Close next.
So if we have such chain:
And
Resources
allocates some resources on Request, all of them should be freed by one of:Timeout
sends Close.Resources
fails Request and sends Close on failure.Current Behavior
Suppose that:
Resources
allocates and frees resources using Request context (e.g. all VPP based chain elements).Server
fails ins.doSomething()
(e.g. heal client is waiting for the monitor update until the Request context timeout).In such case:
Timeout
doesn't send Close, because Request is failed.Resources
cannot free allocates resources during the Close on failure, because Request context is expired.As a result we have resource leak in
Resource
.The text was updated successfully, but these errors were encountered: