Skip to content

Commit

Permalink
signal-upgrade close of closed channel (easegress-io#1190)
Browse files Browse the repository at this point in the history
* use sync.once make sure channel is closed once when meet signal-upgrade

* update
  • Loading branch information
suchen-sci committed Jan 15, 2024
1 parent b910a82 commit db771f8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/api/dynamicmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package api
import (
"net/http"
"sort"
"sync"
"sync/atomic"

"github.com/go-chi/chi/v5"
Expand All @@ -32,8 +33,10 @@ import (
type (
dynamicMux struct {
server *Server
done chan struct{}
router atomic.Value

done chan struct{}
closeOnce sync.Once
}
)

Expand Down Expand Up @@ -136,5 +139,12 @@ func (m *dynamicMux) reloadAPIs() {
}

func (m *dynamicMux) close() {
close(m.done)
// make sure to close channel only once.
// when use "signal-upgrade", easegress will start a new process gracefully,
// which may cause the old process be closed twice.
// here we use sync.Once to make sure the channel is closed only once.
// more discussion here: https://github.com/easegress-io/easegress/issues/1170
m.closeOnce.Do(func() {
close(m.done)
})
}

0 comments on commit db771f8

Please sign in to comment.