fix: flush log when os exit (#46608)

issue: #45640

Signed-off-by: chyezh <chyezh@outlook.com>
This commit is contained in:
Zhen Ye 2025-12-26 14:25:18 +08:00 committed by GitHub
parent ef6d9c25c2
commit 2c2cbe89c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func exitWhenStopTimeout(stop func() error, timeout time.Duration) error {
zap.String("component", paramtable.GetRole()),
zap.Duration("cost", time.Since(start)),
zap.Error(err))
log.Cleanup()
os.Exit(1)
}
return err

View File

@ -622,16 +622,19 @@ func (s *Session) checkKeepaliveTTL(nextKeepaliveInstant time.Time) error {
if err != nil {
if errors.Is(err, v3rpc.ErrLeaseNotFound) {
s.Logger().Error("confirm the lease is not found, the session is expired without activing closing", zap.Error(err))
log.Cleanup()
os.Exit(exitCodeSessionLeaseExpired)
}
if ctx.Err() != nil && errors.Is(context.Cause(ctx), errSessionExpiredAtClientSide) {
s.Logger().Error("session expired at client side, the session is expired without activing closing", zap.Error(err))
log.Cleanup()
os.Exit(exitCodeSessionLeaseExpired)
}
return errors.Wrap(err, "failed to check TTL")
}
if ttlResp.TTL <= 0 {
s.Logger().Error("confirm the lease is expired, the session is expired without activing closing", zap.Error(err))
log.Cleanup()
os.Exit(exitCodeSessionLeaseExpired)
}
s.Logger().Info("check TTL success, try to keep alive...", zap.Int64("ttl", ttlResp.TTL))