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>
... | ... |
@@ -247,6 +247,14 @@ func (s *State) IsPaused() bool { |
247 | 247 |
return res |
248 | 248 |
} |
249 | 249 |
|
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 |
+ |
|
250 | 258 |
// SetRemovalInProgress sets the container state as being removed. |
251 | 259 |
func (s *State) SetRemovalInProgress() error { |
252 | 260 |
s.Lock() |
... | ... |
@@ -52,6 +52,9 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) { |
52 | 52 |
if container.IsPaused() { |
53 | 53 |
return nil, derr.ErrorCodeExecPaused.WithArgs(container.ID) |
54 | 54 |
} |
55 |
+ if container.IsRestarting() { |
|
56 |
+ return nil, derr.ErrorCodeExecRestarting.WithArgs(container.ID) |
|
57 |
+ } |
|
55 | 58 |
return ec, nil |
56 | 59 |
} |
57 | 60 |
} |
... | ... |
@@ -76,6 +79,9 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) { |
76 | 76 |
if container.IsPaused() { |
77 | 77 |
return nil, derr.ErrorCodeExecPaused.WithArgs(name) |
78 | 78 |
} |
79 |
+ if container.IsRestarting() { |
|
80 |
+ return nil, derr.ErrorCodeExecRestarting.WithArgs(name) |
|
81 |
+ } |
|
79 | 82 |
return container, nil |
80 | 83 |
} |
81 | 84 |
|
... | ... |
@@ -733,6 +733,15 @@ var ( |
733 | 733 |
HTTPStatusCode: http.StatusConflict, |
734 | 734 |
}) |
735 | 735 |
|
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 |
+ |
|
736 | 745 |
// ErrorCodeExecRunning is generated when we try to start an exec |
737 | 746 |
// but its already running. |
738 | 747 |
ErrorCodeExecRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{ |