This reverts commit 1326f0cba5f933674e23769de1385d3b0841e758.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -80,7 +80,6 @@ type containerMonitor struct {
|
| 80 | 80 |
// StartMonitor initializes a containerMonitor for this container with the provided supervisor and restart policy |
| 81 | 81 |
// and starts the container's process. |
| 82 | 82 |
func (container *Container) StartMonitor(s supervisor, policy container.RestartPolicy) error {
|
| 83 |
- container.Lock() |
|
| 84 | 83 |
container.monitor = &containerMonitor{
|
| 85 | 84 |
supervisor: s, |
| 86 | 85 |
container: container, |
| ... | ... |
@@ -89,7 +88,6 @@ func (container *Container) StartMonitor(s supervisor, policy container.RestartP |
| 89 | 89 |
stopChan: make(chan struct{}),
|
| 90 | 90 |
startSignal: make(chan struct{}),
|
| 91 | 91 |
} |
| 92 |
- container.Unlock() |
|
| 93 | 92 |
|
| 94 | 93 |
return container.monitor.wait() |
| 95 | 94 |
} |
| ... | ... |
@@ -159,8 +157,6 @@ func (m *containerMonitor) start() error {
|
| 159 | 159 |
} |
| 160 | 160 |
m.Close() |
| 161 | 161 |
}() |
| 162 |
- |
|
| 163 |
- m.container.Lock() |
|
| 164 | 162 |
// reset stopped flag |
| 165 | 163 |
if m.container.HasBeenManuallyStopped {
|
| 166 | 164 |
m.container.HasBeenManuallyStopped = false |
| ... | ... |
@@ -175,20 +171,16 @@ func (m *containerMonitor) start() error {
|
| 175 | 175 |
if err := m.supervisor.StartLogging(m.container); err != nil {
|
| 176 | 176 |
m.resetContainer(false) |
| 177 | 177 |
|
| 178 |
- m.container.Unlock() |
|
| 179 | 178 |
return err |
| 180 | 179 |
} |
| 181 | 180 |
|
| 182 | 181 |
pipes := execdriver.NewPipes(m.container.Stdin(), m.container.Stdout(), m.container.Stderr(), m.container.Config.OpenStdin) |
| 183 |
- m.container.Unlock() |
|
| 184 | 182 |
|
| 185 | 183 |
m.logEvent("start")
|
| 186 | 184 |
|
| 187 | 185 |
m.lastStartTime = time.Now() |
| 188 | 186 |
|
| 189 |
- // don't lock Run because m.callback has own lock |
|
| 190 | 187 |
if exitStatus, err = m.supervisor.Run(m.container, pipes, m.callback); err != nil {
|
| 191 |
- m.container.Lock() |
|
| 192 | 188 |
// if we receive an internal error from the initial start of a container then lets |
| 193 | 189 |
// return it instead of entering the restart loop |
| 194 | 190 |
// set to 127 for container cmd not found/does not exist) |
| ... | ... |
@@ -198,7 +190,6 @@ func (m *containerMonitor) start() error {
|
| 198 | 198 |
if m.container.RestartCount == 0 {
|
| 199 | 199 |
m.container.ExitCode = 127 |
| 200 | 200 |
m.resetContainer(false) |
| 201 |
- m.container.Unlock() |
|
| 202 | 201 |
return derr.ErrorCodeCmdNotFound |
| 203 | 202 |
} |
| 204 | 203 |
} |
| ... | ... |
@@ -207,7 +198,6 @@ func (m *containerMonitor) start() error {
|
| 207 | 207 |
if m.container.RestartCount == 0 {
|
| 208 | 208 |
m.container.ExitCode = 126 |
| 209 | 209 |
m.resetContainer(false) |
| 210 |
- m.container.Unlock() |
|
| 211 | 210 |
return derr.ErrorCodeCmdCouldNotBeInvoked |
| 212 | 211 |
} |
| 213 | 212 |
} |
| ... | ... |
@@ -216,13 +206,11 @@ func (m *containerMonitor) start() error {
|
| 216 | 216 |
m.container.ExitCode = -1 |
| 217 | 217 |
m.resetContainer(false) |
| 218 | 218 |
|
| 219 |
- m.container.Unlock() |
|
| 220 | 219 |
return derr.ErrorCodeCantStart.WithArgs(m.container.ID, utils.GetErrorMessage(err)) |
| 221 | 220 |
} |
| 222 | 221 |
|
| 223 |
- m.container.Unlock() |
|
| 224 | 222 |
logrus.Errorf("Error running container: %s", err)
|
| 225 |
- } // end if |
|
| 223 |
+ } |
|
| 226 | 224 |
|
| 227 | 225 |
// here container.Lock is already lost |
| 228 | 226 |
afterRun = true |
| ... | ... |
@@ -243,14 +231,13 @@ func (m *containerMonitor) start() error {
|
| 243 | 243 |
if m.shouldStop {
|
| 244 | 244 |
return err |
| 245 | 245 |
} |
| 246 |
- m.container.Lock() |
|
| 247 | 246 |
continue |
| 248 | 247 |
} |
| 249 | 248 |
|
| 250 | 249 |
m.logEvent("die")
|
| 251 | 250 |
m.resetContainer(true) |
| 252 | 251 |
return err |
| 253 |
- } // end for |
|
| 252 |
+ } |
|
| 254 | 253 |
} |
| 255 | 254 |
|
| 256 | 255 |
// resetMonitor resets the stateful fields on the containerMonitor based on the |
| ... | ... |
@@ -331,7 +318,7 @@ func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig, pid |
| 331 | 331 |
} |
| 332 | 332 |
} |
| 333 | 333 |
|
| 334 |
- m.container.SetRunningLocking(pid) |
|
| 334 |
+ m.container.SetRunning(pid) |
|
| 335 | 335 |
|
| 336 | 336 |
// signal that the process has started |
| 337 | 337 |
// close channel only if not closed |
| ... | ... |
@@ -179,13 +179,6 @@ func (s *State) getExitCode() int {
|
| 179 | 179 |
return res |
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 |
-// SetRunningLocking locks container and sets it to "running" |
|
| 183 |
-func (s *State) SetRunningLocking(pid int) {
|
|
| 184 |
- s.Lock() |
|
| 185 |
- s.SetRunning(pid) |
|
| 186 |
- s.Unlock() |
|
| 187 |
-} |
|
| 188 |
- |
|
| 189 | 182 |
// SetRunning sets the state of the container to "running". |
| 190 | 183 |
func (s *State) SetRunning(pid int) {
|
| 191 | 184 |
s.Error = "" |
| ... | ... |
@@ -199,7 +192,7 @@ func (s *State) SetRunning(pid int) {
|
| 199 | 199 |
s.waitChan = make(chan struct{})
|
| 200 | 200 |
} |
| 201 | 201 |
|
| 202 |
-// SetStoppedLocking locks the container state and sets it to "stopped". |
|
| 202 |
+// SetStoppedLocking locks the container state is sets it to "stopped". |
|
| 203 | 203 |
func (s *State) SetStoppedLocking(exitStatus *execdriver.ExitStatus) {
|
| 204 | 204 |
s.Lock() |
| 205 | 205 |
s.SetStopped(exitStatus) |
| ... | ... |
@@ -142,15 +142,9 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error) |
| 142 | 142 |
mounts = append(mounts, container.TmpfsMounts()...) |
| 143 | 143 |
|
| 144 | 144 |
container.Command.Mounts = mounts |
| 145 |
- container.Unlock() |
|
| 146 |
- |
|
| 147 |
- // don't lock waitForStart because it has potential risk of blocking |
|
| 148 |
- // which will lead to dead lock, forever. |
|
| 149 | 145 |
if err := daemon.waitForStart(container); err != nil {
|
| 150 |
- container.Lock() |
|
| 151 | 146 |
return err |
| 152 | 147 |
} |
| 153 |
- container.Lock() |
|
| 154 | 148 |
container.HasBeenStartedBefore = true |
| 155 | 149 |
return nil |
| 156 | 150 |
} |