Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TestServiceImpl ¶
type TestServiceImpl struct {
testpb.UnimplementedAnswerServiceServer
}
func (*TestServiceImpl) Greeting ¶
implemented service greeting
Unary handlers that finish quickly do NOT need the rule #13 dual-ctx pattern — the RPC ctx already cancels on client disconnect, and a fast-returning handler naturally drains before shutdown completes. Only interruptible long-running handlers need to observe Service.ShutdownCtx() — see StreamGreeting below for that pattern.
type TestStreamServiceImpl ¶ added in v1.0.8
type TestStreamServiceImpl struct {
testpb.UnimplementedAnswerServerStreamServiceServer
// contains filtered or unexported fields
}
TestStreamServiceImpl demonstrates rule #13 (gRPC handler ctx is client-lifetime, not server-drain-signal). A streaming handler that loops and does interruptible work MUST observe Service.ShutdownCtx() in addition to the per-RPC stream.Context() — otherwise long-lived streams will continue past SIGTERM and break rolling deploys.
The svc reference is wired in from main.go so the handler can call svc.ShutdownCtx(). It may be nil in tests; the orNil helper below makes the select path safe in that case.
func NewTestStreamServiceImpl ¶ added in v1.8.0
func NewTestStreamServiceImpl(svc *service.Service) *TestStreamServiceImpl
NewTestStreamServiceImpl constructs the streaming handler with a reference to the owning *service.Service so StreamGreeting can observe shutdown via svc.ShutdownCtx() per rule #13.
func (*TestStreamServiceImpl) StreamGreeting ¶ added in v1.0.8
func (s *TestStreamServiceImpl) StreamGreeting(in *testpb.Question, stream testpb.AnswerServerStreamService_StreamGreetingServer) error
StreamGreeting demonstrates the rule #13 dual-ctx pattern.
Rule #13: gRPC unary/stream handler ctx is client-lifetime, not server-drain-signal. The stream.Context() that gRPC hands us cancels when the CLIENT goes away, NOT when the server is draining on SIGTERM. A long-running streaming handler that only observes the RPC ctx will keep pumping data through graceful shutdown and prevent the drain window from completing cleanly. To react to server shutdown we must observe a SECOND ctx — Service.ShutdownCtx() — in the same select alongside the RPC ctx.
Both shutdown paths fire ShutdownCtx as of SVC-F7 (2026-04-14): signal-driven exit via awaitOsSigExit AND programmatic GracefulStop / ImmediateStop all route through the unified quit channel, so this dual-ctx pattern is reliable regardless of which path the consumer takes.