Skip to content

feat(abci/server): accept pre-bound listener in socket and gRPC servers - #1

Closed
songgaoye wants to merge 1 commit into
mainfrom
song/socket_server_listener
Closed

feat(abci/server): accept pre-bound listener in socket and gRPC servers#1
songgaoye wants to merge 1 commit into
mainfrom
song/socket_server_listener

Conversation

@songgaoye

Copy link
Copy Markdown
Owner

Summary

  • Add NewSocketServerWithListener and NewGRPCServerWithListener constructors to the ABCI socket and gRPC servers, following the same convention as net/http.Serve and grpc.Server.Serve
  • OnStart skips net.Listen when a listener is already set, so both constructors share the same start path

Motivation

The existing constructors always call net.Listen inside OnStart, which has two drawbacks:

  • TOCTOU: there is a race between selecting a port and binding it — another process can grab the port in that window. A pre-bound listener eliminates the race entirely.
  • Testability: tests must pick a fixed port upfront, risking conflicts in parallel runs. With net.Listen("tcp", "127.0.0.1:0") the OS assigns an ephemeral port, and the caller knows the exact address before the server starts.

Socket-activated processes (e.g. systemd) also rely on passing pre-bound file descriptors, which this enables.

Test plan

  • TestNewSocketServerWithListener: binds an ephemeral port, starts the server via the new constructor, dials it, stops cleanly
  • TestNewGRPCServerWithListener: same pattern for the gRPC server
  • Existing tests continue to pass

@songgaoye songgaoye closed this Jun 1, 2026
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