To effectively solve the problem of upstream error reporting caused by service upgrade/migration, Kitex supports the graceful shutdown function of gRPC Streaming in the new version (v0.12.0).
By setting a reasonable window time, the streams with a lifetime shorter than this window can continue to work until the end, while the streams with a lifetime longer than this window will be forcibly closed.
Before starting the configuration, please obtain the duration distribution of the streams in the current service based on business statistics, and thereby establish a reasonable window time, denoted as graceTime, for example:
When creating the Server, pass server.WithExitWaitTime(graceTime)
.
If not configured, the default is 5 s.
import (
"github.com/cloudwego/kitex/server"
)
const (
graceTime = 600 * time.Second
)
svr := testservice.NewServer(hdl, server.WithExitWaitTime(graceTime))