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

Fix(#1974):fix shutdown InternalSignal default value #2003

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/graceful_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func gracefulShutdownInit() {
filter.Set(constant.GracefulShutdownFilterShutdownConfig, GetShutDown())
}

if GetShutDown().InternalSignal {
if GetShutDown().GetInternalSignal() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, ShutdownSignals...)

Expand Down
13 changes: 10 additions & 3 deletions config/graceful_shutdown_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type ShutdownConfig struct {
// when we try to shutdown the applicationConfig, we will reject the new requests. In most cases, you don't need to configure this.
RejectRequestHandler string `yaml:"reject-handler" json:"reject-handler,omitempty" property:"reject_handler"`
// internal listen kill signal,the default is true.
InternalSignal bool `default:"true" yaml:"internal-signal" json:"internal.signal,omitempty" property:"internal.signal"`
InternalSignal *bool `default:"true" yaml:"internal-signal" json:"internal.signal,omitempty" property:"internal.signal"`
// offline request window length
OfflineRequestWindowTimeout string `yaml:"offline-request-window-timeout" json:"offlineRequestWindowTimeout,omitempty" property:"offlineRequestWindowTimeout"`
// true -> new request will be rejected.
Expand Down Expand Up @@ -124,6 +124,13 @@ func (config *ShutdownConfig) GetConsumerUpdateWaitTime() time.Duration {
return result
}

func (config *ShutdownConfig) GetInternalSignal() bool {
if config.InternalSignal == nil {
return false
}
return *config.InternalSignal
}

func (config *ShutdownConfig) Init() error {
return defaults.Set(config)
}
Expand Down Expand Up @@ -157,12 +164,12 @@ func (scb *ShutdownConfigBuilder) SetRejectRequest(rejectRequest bool) *Shutdown
}

func (scb *ShutdownConfigBuilder) SetInternalSignal(internalSignal bool) *ShutdownConfigBuilder {
scb.shutdownConfig.InternalSignal = internalSignal
scb.shutdownConfig.InternalSignal = &internalSignal
Copy link
Contributor

Choose a reason for hiding this comment

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

不需要加锁保护下吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

应该不需要,没有并发的场景

return scb
}

func (scb *ShutdownConfigBuilder) Build() *ShutdownConfig {
defaults.Set(scb)
defaults.MustSet(scb.shutdownConfig)
return scb.shutdownConfig
}

Expand Down
16 changes: 15 additions & 1 deletion config/graceful_shutdown_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestNewShutDownConfigBuilder(t *testing.T) {
SetOfflineRequestWindowTimeout("13s").
SetRejectRequestHandler("handler").
SetRejectRequest(true).
SetInternalSignal(true).
SetInternalSignal(false).
Build()

assert.Equal(t, config.Prefix(), constant.ShutdownConfigPrefix)
Expand All @@ -86,4 +86,18 @@ func TestNewShutDownConfigBuilder(t *testing.T) {

waitTime := config.GetConsumerUpdateWaitTime()
assert.Equal(t, waitTime, 3*time.Second)

assert.Equal(t, config.GetInternalSignal(), false)
}

func TestGetInternalSignal(t *testing.T) {
config := NewShutDownConfigBuilder().
SetTimeout("10s").
SetStepTimeout("15s").
SetOfflineRequestWindowTimeout("13s").
SetRejectRequestHandler("handler").
SetRejectRequest(true).
Build()

assert.Equal(t, config.GetInternalSignal(), true)
}