mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-03 17:43:49 +03:00
Avoid deadlock (fixes #941)
This commit is contained in:
parent
b35d19d78e
commit
1240690973
1 changed files with 9 additions and 4 deletions
11
caddy.go
11
caddy.go
|
@ -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 {
|
||||||
|
// This awkward for loop is to avoid a deadlock since
|
||||||
|
// inst.Stop() also acquires the instancesMu lock.
|
||||||
|
for {
|
||||||
instancesMu.Lock()
|
instancesMu.Lock()
|
||||||
for _, inst := range instances {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue