mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix possible race condition destroying container
When the sandbox is destroyed, making URPC calls to destroy the container will fail. The code was checking if the sandbox was running before attempting to make the URPC call, but that is racy. PiperOrigin-RevId: 284093764
This commit is contained in:
committed by
gVisor bot
parent
13f0f6069a
commit
40035d7d9c
@@ -1004,16 +1004,22 @@ func (s *Sandbox) ChangeLogging(args control.LoggingArgs) error {
|
||||
// DestroyContainer destroys the given container. If it is the root container,
|
||||
// then the entire sandbox is destroyed.
|
||||
func (s *Sandbox) DestroyContainer(cid string) error {
|
||||
if err := s.destroyContainer(cid); err != nil {
|
||||
// If the sandbox isn't running, the container has already been destroyed,
|
||||
// ignore the error in this case.
|
||||
if s.IsRunning() {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Sandbox) destroyContainer(cid string) error {
|
||||
if s.IsRootContainer(cid) {
|
||||
log.Debugf("Destroying root container %q by destroying sandbox", cid)
|
||||
return s.destroy()
|
||||
}
|
||||
|
||||
if !s.IsRunning() {
|
||||
// Sandbox isn't running anymore, container is already destroyed.
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("Destroying container %q in sandbox %q", cid, s.ID)
|
||||
conn, err := s.sandboxConnect()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user