Skip to content

GRPCServer runs a *grpc.Server without depending on grpc - #86

Merged
pior merged 3 commits into
mainfrom
v1.1/23-server
Oct 6, 2026
Merged

pior merged 3 commits into
mainfrom
v1.1/23-server

Conversation

@pior

@pior pior commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

Adds the second server wrapper that ServerOption was designed for.

GRPCServer(addr, s, opts...) runs a *grpc.Server. It takes an interface with the Serve, GracefulStop and Stop methods, so the module doesn't depend on grpc. It behaves and logs like HTTPServer: listening, draining, then drained, drain timed out or drain failed.

  • Drain: on cancellation it calls GracefulStop. If DrainTimeout expires first, it calls Stop and returns server shutdown: context deadline exceeded.
  • One implementation: HTTPServer and GRPCServer share an unexported server core built from a serve function and a shutdown function.
  • addr is required: a *grpc.Server has no address. Listener(ln) overrides it.
  • HTTPServer still reads server.Addr when Run is called, as on main, so an Addr set after construction is still used.

Integration module

integration/grpc is a separate Go module that tests GRPCServer against a real *grpc.Server: a clean drain, and a drain timeout on a never-ending stream that falls back to Stop. grpc stays out of the runnable module, even as a test dependency. CI runs it as a matrix job (lint, go mod verify, go mod tidy -diff, go test -race), and bud integration runs it locally. gomoddirectives allows its local replace.

The main test job now also runs go mod download and go mod verify.

@pior
pior added this pull request to stack #87 September 27, 2026 16:39
Base automatically changed from v1.1/21-server-options to main September 27, 2026 20:38
@pior
pior force-pushed the v1.1/23-server branch 2 times, most recently from a8a6911 to c35ce77 Compare September 27, 2026 21:37
@pior pior changed the title Server runs any server made of a serve and a shutdown function GRPCServer runs a *grpc.Server without depending on grpc Sep 27, 2026
@pior
pior marked this pull request as ready for review October 6, 2026 19:42
@pior
pior merged commit ccccfa9 into main Oct 6, 2026
3 checks passed
@pior
pior deleted the v1.1/23-server branch October 6, 2026 21:07
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.

1 participant