Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signal-upgrade close of closed channel #1190

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's rare to support reclosable in Easegress, so it's better to add a comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated! please check

close(m.done)
})
}
Loading