Skip to content

Support grpc.so_reuseport in @grpc/grpc-js on Linux #3108

Open

Description

@senutim

Is your feature request related to a problem? Please describe.

We want to run multiple worker threads for one gRPC service, all listening on the same port.

grpc-js currently ignores:

  new grpc.Server({
    'grpc.so_reuseport': 1
  });

so the second worker fails with EADDRINUSE.

This came up before in #794 and #1547. In #1547, Node did not yet expose a JavaScript API for SO_REUSEPORT. It does now:

  http2Server.listen({ host, port, reusePort: true });

Describe the solution you'd like

Make grpc-js honor grpc.so_reuseport when binding a TCP listener.

Something along these lines:

  const listenAddress =
    this.options['grpc.so_reuseport'] === 1 && 'port' in address
      ? { ...address, reusePort: true }
      : address;

  http2Server.listen(listenAddress, callback);

No behavior change unless the option is explicitly set to 1.

Describe alternatives you've considered

We can maintain a local patch-package patch or monkey-patch grpc-js internals, but both depend on private implementation details and need maintenance on grpc-js upgrades.

Keeping one worker per gRPC process works, but prevents worker-thread scaling.

Additional context

This is for several workers of the same service sharing one endpoint, not unrelated services sharing a port.

Linux only is fine for us. We run Node 24.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions