Skip to content
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

Workaround for inconsistency container status #339

Open
wants to merge 1 commit into
base: docker-1.13.1-rhel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,21 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
cli.TrustKeyPath = opts.common.TrustKey

registryService := registry.NewService(cli.Config.ServiceOptions)
containerdRemote, err := libcontainerd.New(cli.getLibcontainerdRoot(), cli.getPlatformRemoteOptions()...)

// libcontainerd.New add hook
hook := func() {
if cli.d == nil {
return
}
for _, c := range cli.d.List() {
c.CheckProcessIsRunning()
}
}
containerdRemote, err := libcontainerd.New(cli.getLibcontainerdRoot(), hook, cli.getPlatformRemoteOptions()...)
if err != nil {
return err
}

signal.Trap(func() {
cli.stop()
<-stopc // wait for daemonCli.start() to return
Expand Down
12 changes: 12 additions & 0 deletions container/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"golang.org/x/net/context"

"github.com/docker/docker/api/types"
"github.com/docker/docker/utils"
"github.com/docker/go-units"
)

Expand Down Expand Up @@ -230,6 +231,17 @@ func (s *State) IsRunning() bool {
return res
}

// CheckProcessIsRunning check the the process of running container is still performed.
func (s *State) CheckProcessIsRunning() {
if !s.IsRunning() {
return
}
if !utils.IsProcessAlive(s.Pid) {
// TODO: force set exitcode:1, better to define new exitcode
s.SetStopped(&ExitStatus{ExitCode: 1})
}
}

// GetPID holds the process id of a container.
func (s *State) GetPID() int {
s.Lock()
Expand Down
9 changes: 7 additions & 2 deletions libcontainerd/remote_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ type remote struct {
oomScore int
maxHealthCheckRetries int
restoreFromTimestamp *timestamp.Timestamp
handleContainerdHook func()
}

// New creates a fresh instance of libcontainerd remote.
func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
func New(stateDir string, hook func(), options ...RemoteOption) (_ Remote, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("Failed to connect to containerd. Please make sure containerd is installed in your PATH or you have specified the correct address. Got error: %v", err)
Expand All @@ -75,6 +76,7 @@ func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
daemonPid: -1,
eventTsPath: filepath.Join(stateDir, eventTimestampFilename),
}
r.handleContainerdHook = hook
for _, option := range options {
if err := option.Apply(r); err != nil {
return nil, err
Expand Down Expand Up @@ -117,7 +119,6 @@ func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
logrus.Errorf("libcontainerd: failed to convert timestamp: %q", err)
}
r.restoreFromTimestamp = tsp

go r.handleConnectionChange()

if err := r.startEventsMonitor(); err != nil {
Expand Down Expand Up @@ -179,6 +180,10 @@ func (r *remote) handleConnectionChange() {
if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
logrus.Errorf("libcontainerd: error restarting containerd: %v", err)
}
// Workaround to fix inconsistency stopped status
go func() {
r.handleContainerdHook()
}()
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion libcontainerd/remote_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (r *remote) UpdateOptions(opts ...RemoteOption) error {

// New creates a fresh instance of libcontainerd remote. On Windows,
// this is not used as there is no remote containerd process.
func New(_ string, _ ...RemoteOption) (Remote, error) {
func New(_ string, _ func(), _ ...RemoteOption) (Remote, error) {
return &remote{}, nil
}

Expand Down