Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 1d2208f

Browse files
committed
Forbid exec a restarting container
Currently if we exec a restarting container, client will fail silently, and daemon will print error that container can't be found which is not a very meaningful prompt to user. This commit will stop user from exec a restarting container and gives more explicit error message. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
1 parent e5b5c0e commit 1d2208f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

container/state.go

+8
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ func (s *State) IsPaused() bool {
247247
return res
248248
}
249249

250+
// IsRestarting returns whether the container is restarting or not.
251+
func (s *State) IsRestarting() bool {
252+
s.Lock()
253+
res := s.Restarting
254+
s.Unlock()
255+
return res
256+
}
257+
250258
// SetRemovalInProgress sets the container state as being removed.
251259
func (s *State) SetRemovalInProgress() error {
252260
s.Lock()

daemon/exec.go

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
5252
if container.IsPaused() {
5353
return nil, derr.ErrorCodeExecPaused.WithArgs(container.ID)
5454
}
55+
if container.IsRestarting() {
56+
return nil, derr.ErrorCodeExecRestarting.WithArgs(container.ID)
57+
}
5558
return ec, nil
5659
}
5760
}
@@ -76,6 +79,9 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
7679
if container.IsPaused() {
7780
return nil, derr.ErrorCodeExecPaused.WithArgs(name)
7881
}
82+
if container.IsRestarting() {
83+
return nil, derr.ErrorCodeExecRestarting.WithArgs(name)
84+
}
7985
return container, nil
8086
}
8187

errors/daemon.go

+9
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,15 @@ var (
733733
HTTPStatusCode: http.StatusConflict,
734734
})
735735

736+
// ErrorCodeExecRestarting is generated when we try to start an exec
737+
// but the container is restarting.
738+
ErrorCodeExecRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{
739+
Value: "EXECRESTARTING",
740+
Message: "Container %s is restarting, wait until the container is running",
741+
Description: "An attempt to start an 'exec' was made, but the owning container is restarting",
742+
HTTPStatusCode: http.StatusConflict,
743+
})
744+
736745
// ErrorCodeExecRunning is generated when we try to start an exec
737746
// but its already running.
738747
ErrorCodeExecRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{

0 commit comments

Comments
 (0)