Skip to content

Commit 3539e2c

Browse files
committed
RHINENG-21760: postpone context cancellation after SIGTERM
Add a short delay, a portion of the grace period between SIGTERM and SIGKILL, before context cancellation to allow the in-flight requests to finish and thus prevent gRPC CANCELED errors from Kessel middleware.
1 parent 0f8938c commit 3539e2c

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

base/base.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"os/signal"
88
"strings"
99
"syscall"
10+
"time"
1011

1112
"github.com/gin-gonic/gin"
1213
)
1314

1415
const VMaaSAPIPrefix = "/api/v3"
1516
const RBACApiPrefix = "/api/rbac/v1"
17+
const defaultGracePeriod = 30 * time.Second
1618

1719
var Context context.Context
1820
var CancelContext context.CancelFunc
@@ -25,8 +27,9 @@ func HandleSignals() {
2527
c := make(chan os.Signal, 1)
2628
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
2729
go func() {
28-
<-c
29-
utils.LogInfo("SIGTERM/SIGINT received")
30+
sig := <-c
31+
utils.LogInfo("starting grace period for " + sig.String())
32+
time.Sleep(defaultGracePeriod / 3)
3033
CancelContext()
3134
utils.LogInfo("SIGTERM/SIGINT handled")
3235
}()

0 commit comments

Comments
 (0)