Skip to content

Transport: add configurable inbound endpoint port-range - #121

Merged
oktal merged 3 commits into
masterfrom
feat/transport/port-range
Oct 14, 2026
Merged

oktal merged 3 commits into
masterfrom
feat/transport/port-range

Conversation

@oktal

@oktal oktal commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Context

A service bus peer can be configured to listen to a particular endpoint.
We currently support a configuration endpoint syntax where the port can either be a wildcard, eg tcp://*:*, letting the OS chose an ephemeral port, or a single, fixed port, eg tcp://*:14001

Motivation

We want to support specifying a port range in a configuration endpoint. This allows for easily discriminating zebus-specific traffic.

Changes

This MR introduces a new tcp://<host>:[<start>..<end>] syntax to configure the inbound endpoint the peer will listen on.
A [<start>..<end>] range can be configured as a port. The system will then pick the first available port in the range by attempting to bind to any single one.

A new ZmqPort discriminated enum type has been introduced to represent such a port, that can take the following values:

  • ZmqPort.Wildcard, represents a * wildcard port
  • ZmqPort.Single(port) represents a fixed <port> port
  • ZmqPort.Range(start, end) represents a [<start>..<end>] port range

A ZmqSocket.TryBind operation has been introduced to attempt to bind to a given endpoint. When the operation returns EADDRINUSE, we simply attempt the next port in the range.

Two services starting at the same time on the same machine will compete on the same range, but they should all end up succeeding, given a reasonably-sized range.

@ocoanet

ocoanet commented Sep 18, 2026

Copy link
Copy Markdown
Member

nitpick: It seems weird that a type named ZmqPort can represent a wildcard or a range. I would prefer a more explicit name like ZmqPortSelector or ZmqPortSpec.

On Windows, zmq remaps Windows WSAEADDRINUSE (10048) to errno EADDRINUSE
(100)
@oktal

oktal commented Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

nitpick: It seems weird that a type named ZmqPort can represent a wildcard or a range. I would prefer a more explicit name like ZmqPortSelector or ZmqPortSpec.

To me it seems natural because I view it as a real, discriminated union type, but I understand your feeling.

I like ZmqPortSpec, the semantic would be, you have a spec, and then you get back a ZmqPort (or ushort) after resolution, even though we don't really need the port value, I think.

@oktal

oktal commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

I renamed ZmqPort to ZmqPortSpec

Comment thread src/Abc.Zebus/Transport/ZmqInboundSocket.cs
Comment thread src/Abc.Zebus.Tests/Transport/ZmqEndPointTests.cs
@oktal
oktal merged commit a7a645e into master Oct 14, 2026
5 of 6 checks passed
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.

2 participants