-
Notifications
You must be signed in to change notification settings - Fork 1k
refactor: migrate graceful shutdown config to global #3386
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
Merged
Alanxtl
merged 5 commits into
apache:develop
from
Oxidaner:migrate-graceful-shutdown-config-global
Jun 19, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
268b9ff
refactor: migrate graceful shutdown config to global
Oxidaner dcc76e8
refactor: remove config dependency from graceful shutdown
Oxidaner a275c34
refactor: centralize shutdown config defaults
Oxidaner a565a0d
fix: align graceful shutdown config logging
Oxidaner 26cb6fd
fix: protocol/triple/triple_protocol/triple_ext_test.go gRPC streamin…
Oxidaner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,141 +17,18 @@ | |
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "time" | ||
| ) | ||
|
|
||
| import ( | ||
| "github.com/creasty/defaults" | ||
|
|
||
| "github.com/dubbogo/gost/log/logger" | ||
|
|
||
| "go.uber.org/atomic" | ||
| ) | ||
|
|
||
| import ( | ||
| "dubbo.apache.org/dubbo-go/v3/common/constant" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultTimeout = 60 * time.Second | ||
| defaultStepTimeout = 3 * time.Second | ||
| defaultNotifyTimeout = 5 * time.Second | ||
| defaultConsumerUpdateWaitTime = 3 * time.Second | ||
| defaultOfflineRequestWindowTimeout = 3 * time.Second | ||
| "dubbo.apache.org/dubbo-go/v3/global" | ||
| ) | ||
|
|
||
| // ShutdownConfig is used as configuration for graceful shutdown | ||
| type ShutdownConfig struct { | ||
| /* | ||
| * Total timeout. Even though we don't release all resources, | ||
| * the applicationConfig will shutdown if the costing time is over this configuration. The unit is ms. | ||
| * default value is 60 * 1000 ms = 1 minutes | ||
| * In general, it should be bigger than 3 * StepTimeout. | ||
| */ | ||
| Timeout string `default:"60s" yaml:"timeout" json:"timeout,omitempty" property:"timeout"` | ||
| /* | ||
| * the timeout on each step. You should evaluate the response time of request | ||
| * and the time that client noticed that server shutdown. | ||
| * For example, if your client will received the notification within 10s when you start to close server, | ||
| * and the 99.9% requests will return response in 2s, so the StepTimeout will be bigger than(10+2) * 1000ms, | ||
| * maybe (10 + 2*3) * 1000ms is a good choice. | ||
| */ | ||
| StepTimeout string `default:"3s" yaml:"step-timeout" json:"step.timeout,omitempty" property:"step.timeout"` | ||
|
|
||
| /* | ||
| * NotifyTimeout means the timeout budget for actively notifying long-connection consumers | ||
| * during graceful shutdown. It only controls the notify step and should not be coupled to | ||
| * request draining timeouts. | ||
| */ | ||
| NotifyTimeout string `default:"5s" yaml:"notify-timeout" json:"notify.timeout,omitempty" property:"notify.timeout"` | ||
|
|
||
| /* | ||
| * ConsumerUpdateWaitTime means when provider is shutting down, after the unregister, time to wait for client to | ||
| * update invokers. During this time, incoming invocation can be treated normally. | ||
| */ | ||
| ConsumerUpdateWaitTime string `default:"3s" yaml:"consumer-update-wait-time" json:"consumerUpdate.waitTIme,omitempty" property:"consumerUpdate.waitTIme"` | ||
| // 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"` | ||
| // offline request window length | ||
| OfflineRequestWindowTimeout string `default:"3s" yaml:"offline-request-window-timeout" json:"offlineRequestWindowTimeout,omitempty" property:"offlineRequestWindowTimeout"` | ||
| // true -> new request will be rejected. | ||
| RejectRequest atomic.Bool | ||
| // active invocation | ||
| ConsumerActiveCount atomic.Int32 | ||
| ProviderActiveCount atomic.Int32 | ||
|
|
||
| // provider last received request timestamp | ||
| ProviderLastReceivedRequestTime atomic.Time | ||
| } | ||
|
|
||
| // Prefix dubbo.shutdown | ||
| func (config *ShutdownConfig) Prefix() string { | ||
| return constant.ShutdownConfigPrefix | ||
| } | ||
|
|
||
| func (config *ShutdownConfig) GetTimeout() time.Duration { | ||
| result, err := time.ParseDuration(config.Timeout) | ||
| if err != nil { | ||
| logger.Errorf("The Timeout configuration is invalid: %s, and we will use the default value: %s, err: %v", | ||
| config.Timeout, defaultTimeout.String(), err) | ||
| return defaultTimeout | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func (config *ShutdownConfig) GetStepTimeout() time.Duration { | ||
| result, err := time.ParseDuration(config.StepTimeout) | ||
| if err != nil { | ||
| logger.Errorf("The StepTimeout configuration is invalid: %s, and we will use the default value: %s, err: %v", | ||
| config.StepTimeout, defaultStepTimeout.String(), err) | ||
| return defaultStepTimeout | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func (config *ShutdownConfig) GetNotifyTimeout() time.Duration { | ||
| result, err := time.ParseDuration(config.NotifyTimeout) | ||
| if err != nil { | ||
| logger.Errorf("The NotifyTimeout configuration is invalid: %s, and we will use the default value: %s, err: %v", | ||
| config.NotifyTimeout, defaultNotifyTimeout.String(), err) | ||
| return defaultNotifyTimeout | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func (config *ShutdownConfig) GetOfflineRequestWindowTimeout() time.Duration { | ||
| result, err := time.ParseDuration(config.OfflineRequestWindowTimeout) | ||
| if err != nil { | ||
| logger.Errorf("The OfflineRequestWindowTimeout configuration is invalid: %s, and we will use the default value: %s, err: %v", | ||
| config.OfflineRequestWindowTimeout, defaultOfflineRequestWindowTimeout.String(), err) | ||
| return defaultOfflineRequestWindowTimeout | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func (config *ShutdownConfig) GetConsumerUpdateWaitTime() time.Duration { | ||
| result, err := time.ParseDuration(config.ConsumerUpdateWaitTime) | ||
| if err != nil { | ||
| logger.Errorf("The ConsumerUpdateTimeout configuration is invalid: %s, and we will use the default value: %s, err: %v", | ||
| config.ConsumerActiveCount.Load(), defaultConsumerUpdateWaitTime.String(), err) | ||
| return defaultConsumerUpdateWaitTime | ||
| } | ||
| 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) | ||
| } | ||
|
Comment on lines
-44
to
-154
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不用删 到时候我们直接把config这个包删掉 |
||
| // ShutdownConfig is kept as a compatibility alias for global.ShutdownConfig. | ||
| // Use global.ShutdownConfig directly in new code. Field documentation lives on | ||
| // global.ShutdownConfig because it owns the graceful shutdown configuration. | ||
| type ShutdownConfig = global.ShutdownConfig | ||
|
|
||
| type ShutdownConfigBuilder struct { | ||
| shutdownConfig *ShutdownConfig | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不用删 到时候我们直接把compat这个文件删掉