Skip to content

Commit

Permalink
fix RequestsFinished not working bug
Browse files Browse the repository at this point in the history
  • Loading branch information
justxuewei committed Jun 12, 2021
1 parent 29b7f6d commit b650fa1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/graceful_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func waitForReceivingRequests() {
// ignore this step
return
}
providerConfig.ShutdownConfig.GracefulShutdownStarted = true
waitingProcessedTimeout(providerConfig.ShutdownConfig)
}

Expand All @@ -173,6 +174,7 @@ func waitForSendingRequests() {
// ignore this step
return
}
consumerConfig.ShutdownConfig.GracefulShutdownStarted = true
waitingProcessedTimeout(consumerConfig.ShutdownConfig)
}

Expand Down
3 changes: 2 additions & 1 deletion config/graceful_shutdown_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ type ShutdownConfig struct {
StepTimeout string `default:"10s" yaml:"step_timeout" json:"step.timeout,omitempty" property:"step.timeout"`
// when we try to shutdown the application, 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"`
// true -> graceful shutdown started
GracefulShutdownStarted bool
// true -> new request will be rejected.
RejectRequest bool

// true -> all requests had been processed. In provider side it means that all requests are returned response to clients
// In consumer side, it means that all requests getting response from servers
RequestsFinished bool
Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/graceful_shutdown_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (gf *gracefulShutdownFilter) Invoke(ctx context.Context, invoker protocol.I
func (gf *gracefulShutdownFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
atomic.AddInt32(&gf.activeCount, -1)
// although this isn't thread safe, it won't be a problem if the gf.rejectNewRequest() is true.
if gf.shutdownConfig != nil && gf.activeCount <= 0 {
if gf.shutdownConfig != nil && gf.shutdownConfig.GracefulShutdownStarted && gf.activeCount <= 0 {
gf.shutdownConfig.RequestsFinished = true
}
return result
Expand Down

0 comments on commit b650fa1

Please sign in to comment.