mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-31 15:51:09 +00:00
Clean up leaking goroutines and safer Start()/Stop()
This commit is contained in:
parent
1818b1ea62
commit
6762df415c
6 changed files with 90 additions and 42 deletions
|
|
@ -66,6 +66,7 @@ func New(addr string, configs []Config) (*Server, error) {
|
|||
// into sync.WaitGroup.Wait() - basically, an add
|
||||
// with a positive delta must be guaranteed to
|
||||
// occur before Wait() is called on the wg.
|
||||
// In a way, this kind of acts as a safety barrier.
|
||||
s.httpWg.Add(1)
|
||||
|
||||
// Set up each virtualhost
|
||||
|
|
@ -228,12 +229,12 @@ func (s *Server) Stop() error {
|
|||
// Wait for remaining connections to finish or
|
||||
// force them all to close after timeout
|
||||
select {
|
||||
case <-time.After(5 * time.Second): // TODO: configurable?
|
||||
case <-time.After(5 * time.Second): // TODO: make configurable?
|
||||
case <-done:
|
||||
}
|
||||
}
|
||||
|
||||
// Close the listener now; this stops the server and
|
||||
// Close the listener now; this stops the server without delay
|
||||
s.listenerMu.Lock()
|
||||
err := s.listener.Close()
|
||||
s.listenerMu.Unlock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue