Skip to content

Allow stopping of paused container#34027

Merged
coolljt0725 merged 1 commit into
moby:masterfrom
cpuguy83:15853_allow_stopping_paused_container
Jul 13, 2017
Merged

Allow stopping of paused container#34027
coolljt0725 merged 1 commit into
moby:masterfrom
cpuguy83:15853_allow_stopping_paused_container

Conversation

@cpuguy83

@cpuguy83 cpuguy83 commented Jul 9, 2017

Copy link
Copy Markdown
Member

When a container is paused, signals are sent once the container has been
unpaused.
Instead of forcing the user to unpause a container before they can ever
send a signal, allow the user to send the signals, and in the case of a
stop signal, automatically unpause the container afterwards.

This is much safer than unpausing the container first then sending a
signal (what a user is currently forced to do), as the container may be
paused for very good reasons and should not be unpaused except for
stopping.
Note that not even SIGKILL is possible while a process is paused,
but it is killed the instant it is unpaused.

Closes #15853
Closes #28366

@boaz0 boaz0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@cpuguy83
cpuguy83 force-pushed the 15853_allow_stopping_paused_container branch from 2793589 to f07b477 Compare July 9, 2017 19:47
@thaJeztah

Copy link
Copy Markdown
Member

ping @coolljt0725 - guess you want to have a look

@coolljt0725

Copy link
Copy Markdown
Contributor

I like this, 👍 LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

missing e

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's web 2.0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

@vieux

vieux commented Jul 10, 2017

Copy link
Copy Markdown
Contributor

SGTM

@cpuguy83
cpuguy83 force-pushed the 15853_allow_stopping_paused_container branch from f07b477 to 4dd579a Compare July 10, 2017 14:00
@thaJeztah

Copy link
Copy Markdown
Member

powerpc failing on #34051

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gee, that kill.go file is really difficult to follow, there's a lot of weird logic in there.

Looking at this, I wonder why we have all the conditions to determine if we want or don't want to unpause the container.

Can't we simply modify daemon.kill() to:

func (daemon *Daemon) kill(c *containerpkg.Container, sig int) error {
	if err := daemon.containerd.Signal(c.ID, sig); err != nil {
		return err
	}
	if c.Paused {
		// above kill signal will be sent once resume is finished
		if err := daemon.containerd.Resume(c.ID); err != nil {
			logrus.Warn("Cannot unpause container %s: %s", c.ID, err)
		}
	}
	return nil
}

Basically; if we want to send a signal to the container, we unpause (un-freeze) it afterwards, otherwise the signal never reaches the process.

Are there any conditions we can think of where that is not the desired behaviour?

Comment thread daemon/kill.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you swap the if/else here?

if daemon.IsShuttingDown() {
    unpause = container.Paused
} else {
    container.HasBeenManuallyStopped = true
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed else.

Comment thread daemon/kill.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having a bit of trouble understanding this case;

  • if the container is not stopped due to the daemon is shutting down, it's "manually stopped" ✅
  • if the container is stopped due to the daemon shutting down, we have to unpause ❓

Isn't unpause always needed if it is paused?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, unpause is only needed for kill signals.
In the case where the daemon is not shutting down, it's already going to be set. But we also need to make sure that when the daemon is shutting down that we set it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But, I guess it should already be set in both cases since it should be a stop sig on shutdown.

Comment thread daemon/kill.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like we try to resume the container, even if the daemon.kill() above returned "container not found" or "no such process"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

When a container is paused, signals are sent once the container has been
unpaused.
Instead of forcing the user to unpause a container before they can ever
send a signal, allow the user to send the signals, and in the case of a
stop signal, automatically unpause the container afterwards.

This is much safer than unpausing the container first then sending a
signal (what a user is currently forced to do), as the container may be
paused for very good reasons and should not be unpaused except for
stopping.
Note that not even SIGKILL is possible while a process is paused,
but it is killed the instant it is unpaused.

Signed-off-by: Brian Goff <[email protected]>
@cpuguy83
cpuguy83 force-pushed the 15853_allow_stopping_paused_container branch from 4dd579a to c3feb04 Compare July 12, 2017 14:35
@cpuguy83

Copy link
Copy Markdown
Member Author

@thaJeztah I think we only want to unpause if it's a stop-type signal. signal.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thaJeztah

Copy link
Copy Markdown
Member

ping @coolljt0725 @vieux PTAL

@coolljt0725

Copy link
Copy Markdown
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants