-
Notifications
You must be signed in to change notification settings - Fork 552
[Local] Allow for graceful termination #3823
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
[Local] Allow for graceful termination #3823
Conversation
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.
LGTM with a small suggestion
pkg/platform/local/platform.go
Outdated
"functionName", createFunctionOptions.FunctionConfig.Meta.Name, | ||
"containerID", container.ID) | ||
if err := p.dockerClient.StopContainer(container.ID); err != nil { | ||
if err := p.dockerClient.StopContainer(container.ID, int(p.GetConfig().Local.FunctionContainersGracefulTerminationTimeout.Seconds())); err != 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.
I suggest to add a handler function- p.GetConfig().GetFunctionContainersGracefulTerminationTimeout
(or shorter name) to verifies backward compitibilty if this value is missing, like this for example
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.
@weilerN I believe those are different scenarios. I don't see any BC issues here, we always enrich if it's empty in enrich platform step.
pkg/platform/local/platform.go
Outdated
if err := p.dockerClient.StopContainer(container.ID, int(p.GetConfig().Local.FunctionContainersGracefulTerminationTimeout.Seconds())); err != nil { | ||
return 0, errors.Wrap(err, "Failed to stop a container") |
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.
If 1 container fails but there are still others left, we'll skip them don't try to stop them.
I know that was the previous implementation, but maybe we can continue before failing
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.
agree, will change that
…o graceful-termnination-local
…lways delete a function afterwards
pkg/platform/local/platform.go
Outdated
wg.Add(1) | ||
go func() { | ||
defer wg.Done() |
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.
wg.Go()
?
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.
LGTM, minor suggestion
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.
Looking good, a few minor comments
if errPtr := errDuringStop.Load(); errPtr != nil { | ||
return *errPtr | ||
} | ||
return 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.
return nil | |
p.Logger.InfoWithCtx(ctx, "Successfully deleted function", | |
"name", functionName) | |
return nil |
// no need to fail the entire operation if stopping failed | ||
// we will retry to stop with SIGKILL below | ||
if err = p.dockerClient.StopContainer(containerInfo.ID, int(p.GetConfig().Local.FunctionContainersGracefulTerminationTimeout.Seconds())); err != nil { | ||
errDuringStop.CompareAndSwap(nil, &err) |
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.
If multiple containers fail to stop, only the first error is returned. I’d suggest collecting all errors instead of keeping just the first one.
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 it's fine to return only the first one as we anyway logged the others
📝 Description
Bug was found during writing tests in #3821
We did
docker rm -f
instead ofdocker stop
, which didn’t allow to run termination callback properlyDocker stop docs: docker container stop
docker rm docs: docker container rm
✅ Checklist
🧪 Testing
tested as part of #3821
🔗 References
🚨 Breaking Changes?