Skip to content

server/grpc: add configurable graceful shutdown timeout (v4 & v5)#163

Open
Grantmartin2002 wants to merge 2 commits intogo-micro:mainfrom
Grantmartin2002:feat/configurable-graceful-stop-timeout
Open

server/grpc: add configurable graceful shutdown timeout (v4 & v5)#163
Grantmartin2002 wants to merge 2 commits intogo-micro:mainfrom
Grantmartin2002:feat/configurable-graceful-stop-timeout

Conversation

@Grantmartin2002
Copy link
Copy Markdown

Summary

  • Add GracefulStopTimeout server option to configure how long the gRPC server waits for in-flight requests to complete during graceful shutdown
  • Applied to both v4 and v5 plugins
  • Defaults to time.Second for backwards compatibility

Problem

The gRPC server has a hardcoded 1-second timeout after calling GracefulStop() before forcefully calling Stop(). For applications with long-lived gRPC streams (e.g., server-side streaming in Kubernetes), this causes active streams to be terminated with ECONNRESET during rolling updates, even when terminationGracePeriodSeconds allows for graceful draining.

Usage

import (
    grpcsrv "github.com/go-micro/plugins/v4/server/grpc"
)

srv := micro.NewService(
    micro.Server(grpcsrv.NewServer(
        grpcsrv.GracefulStopTimeout(3 * time.Minute),
    )),
)

Changes

  • v4/server/grpc/options.go — add GracefulStopTimeout option and context key
  • v4/server/grpc/grpc.go — read option, fall back to time.Second
  • v5/server/grpc/options.go — same
  • v5/server/grpc/grpc.go — same

Fixes #162

grantmartin2002-oss and others added 2 commits April 9, 2026 18:59
The gRPC server previously had a hardcoded 1-second timeout after
calling GracefulStop() before forcefully terminating connections with
Stop(). This is insufficient for applications with long-lived gRPC
streams that need time to drain during shutdown.

Add a GracefulStopTimeout option that allows users to configure how
long the server waits for in-flight requests to complete. Defaults
to 1 second for backwards compatibility.

Fixes go-micro#162

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server/grpc: Hardcoded 1s graceful shutdown timeout causes active gRPC streams to be forcefully terminated

1 participant