Commit 12406909 authored by Matthew Holt's avatar Matthew Holt

Avoid deadlock (fixes #941)

parent b35d19d7
...@@ -696,14 +696,19 @@ func loadServerBlocks(serverType, filename string, input io.Reader) ([]caddyfile ...@@ -696,14 +696,19 @@ func loadServerBlocks(serverType, filename string, input io.Reader) ([]caddyfile
// instances after stopping is completed. Do not re-use any // instances after stopping is completed. Do not re-use any
// references to old instances after calling Stop. // references to old instances after calling Stop.
func Stop() error { func Stop() error {
instancesMu.Lock() // This awkward for loop is to avoid a deadlock since
for _, inst := range instances { // inst.Stop() also acquires the instancesMu lock.
for {
instancesMu.Lock()
if len(instances) == 0 {
break
}
inst := instances[0]
instancesMu.Unlock()
if err := inst.Stop(); err != nil { if err := inst.Stop(); err != nil {
log.Printf("[ERROR] Stopping %s: %v", inst.serverType, err) log.Printf("[ERROR] Stopping %s: %v", inst.serverType, err)
} }
} }
instances = []*Instance{}
instancesMu.Unlock()
return nil return nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment