Skip to content

Commit

Permalink
Merge pull request #2003 from zhaoyunxing92/default
Browse files Browse the repository at this point in the history
Fix(#1974):fix shotdown InternalSignal default value
  • Loading branch information
zhaoyunxing92 committed Aug 10, 2022
2 parents 88d2f1b + aab693f commit bad8cf7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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
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)
}

0 comments on commit bad8cf7

Please sign in to comment.