Skip to content

Commit

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

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

Expand Down
2 changes: 0 additions & 2 deletions config/graceful_shutdown_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ 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
Expand Down
5 changes: 4 additions & 1 deletion filter/filter_impl/graceful_shutdown_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ func (gf *gracefulShutdownFilter) Invoke(ctx context.Context, invoker protocol.I
return gf.getRejectHandler().RejectedExecution(invoker.GetURL(), invocation)
}
atomic.AddInt32(&gf.activeCount, 1)
if gf.shutdownConfig != nil && gf.activeCount > 0 {
gf.shutdownConfig.RequestsFinished = false
}
return invoker.Invoke(ctx, invocation)
}

// OnResponse reduces the number of active processes then return the process result
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.shutdownConfig.GracefulShutdownStarted && gf.activeCount <= 0 {
if gf.shutdownConfig != nil && gf.activeCount <= 0 {
gf.shutdownConfig.RequestsFinished = true
}
return result
Expand Down

0 comments on commit f1879b4

Please sign in to comment.