Skip to content

Support actors listening on multiple ports #265

Closed

Description

Today we only support actors listening on port 80. This is hard-coded in atenet (

targetAddr := net.JoinHostPort(workerIP, "80")
).

This task is to allow actor containers to listen on multiple ports.

I guess one open question is how the router deals with? Will it add listeners dynamically as actor templates are created? Will the DNS names be extended to include the port in the name (some sandboxing tools do this).

Activity

  1. BenTheElder commented on Jun 17, 2026

    @BenTheElder
    Collaborator

    See also: #240 (it's also hardcoded in ateom at the moment, but I think we can/should lift that part)

  2. added
    prio/P2
    and removed
    prio/P2
    on Jun 17, 2026
  3. rogeroger-yu commented on Jun 24, 2026

    @rogeroger-yu

    One concrete design that fits this issue is to encode the target actor port in the left-most DNS label, while preserving the existing host format as the default-port path.

    Proposed routing format:

    <actor-id>.actors.resources.substrate.ate.dev            -> <worker-ip>:80
    <port>-<actor-id>.actors.resources.substrate.ate.dev     -> <worker-ip>:<port>
    

    Examples:

    my-actor.actors.resources.substrate.ate.dev        -> my-actor on port 80
    8080-my-actor.actors.resources.substrate.ate.dev   -> my-actor on port 8080
    49983-sbx1.actors.resources.substrate.ate.dev      -> sbx1 on port 49983
    

    Why this shape:

    • It does not require dynamic listener creation in Envoy or atenet.
    • It should work with the existing wildcard DNS shape because the host still ends in actors.resources.substrate.ate.dev.
    • It is backwards compatible: hosts without a numeric prefix keep routing to port 80.
    • It matches the convention used by several sandbox systems where a sandbox service port is encoded in the hostname.
    • It enables generic multi-service actors, not just one specific SDK or compatibility layer.

    Implementation sketch:

    1. Extend the actor-host parsing helper in cmd/atenet/internal/router/extproc_in.go so it returns both actorID and port.
    2. If the left-most label matches ^(\d+)-(.+)$, parse the leading digits as the port and the remainder as the actor ID.
    3. If there is no numeric prefix, keep the existing behavior and default the port to 80.
    4. Validate the parsed port is in 1..65535; invalid ports should fail routing rather than falling back silently.
    5. In cmd/atenet/internal/router/extproc.go, replace the hardcoded net.JoinHostPort(workerIP, "80") with net.JoinHostPort(workerIP, parsedPort).
    6. Add unit tests for default-port routing, prefixed-port routing, invalid ports, and ambiguous labels.

    The main ambiguity is actor IDs that themselves start with <digits>-, since DNS-1123 allows that. I think the router should use a simple deterministic rule: if the first label matches ^(\d+)-(.+)$, it is treated as a port-prefixed actor host. Clients or higher-level tools that generate actor IDs for multi-port access can avoid IDs beginning with <digits>-. Existing actor IDs that do start with digits still work on the default route as long as the label does not start with <digits>-; if they do, callers can use the default unprefixed host only.

    This would also support higher-level sandbox runtimes that expose multiple in-actor services, for example command/filesystem API, code execution API, VNC/noVNC, user HTTP servers, or debugging endpoints, without requiring every actor image to run an extra in-actor reverse proxy just to multiplex ports.

  4. bowei commented on Jun 24, 2026

    @bowei
    Collaborator

    Couple of notes:

    • I see you mentioned this is common pattern for some of the sandbox providers -- any references? I am a bit concerned if we don't allow for dynamic ports this will be significant friction for users. If this actually well-supported, then doing this through DNS is less of a concern.
    • Would it make more sense to extend the dns name vs adding it to the ID label? So the name would be: port-<port>.<actor id>.actors.resources.substrate.ate.dev:
      • It still allows for the full DNS label for the actors ID.
      • No interference between port and id and we could support direct access to the port on the current actor dns name as well.
    • There are workarounds for port handling -- we can use transparent port rewriting (outside Envoy) used by meshes and have Envoy read the original port, so this is less of a concern re: dynamic updates to the router component.
  5. thockin commented on Jun 24, 2026

    @thockin
    Collaborator

    It is backwards compatible: hosts without a numeric prefix keep routing to port 80.

    Unfortunately, it seems ambiguous, unless I am missing something. Specifically, I can create an actor named "foo" or "80-foo" or "8080-80-88-foo" and those are all valid actor names. How then do you parse out the port number? In fact, I can create an actor named "80" which is weird, IMO, but is a valid DNS label.

    I think Bowei Du (@bowei) is right - something like 80.<actor>.actors... is needed. At some point we will need to revisit the overall domain, but in the meantime...

    Do we want to encode this as <portnum>.<actor>.actors... (implying the only prefix is a port number) or more generally like port-<portnum>.<actor>.actors..., which is more verbose but allows potentially other metadata?

  6. bowei commented on Jun 25, 2026

    @bowei
    Collaborator

    One more thing IMO is super important -- this is very much a user friction, interop story where we should check whether or not someone can bring their framework with no or minor modifications and use it with Substrate.

  7. rogeroger-yu commented on Jun 29, 2026

    @rogeroger-yu

    Bowei Du (@bowei) on references — E2B is a concrete example, and it answers the dynamic-port concern directly. Its public URL is https://<port>-<sandboxId>.e2b.app (sandbox.getHost(port) is just client-side string assembly), and the
    port routing happens entirely in their edge proxy: it parses <port> and <sandboxId> from the hostname at request time, finds the sandbox, and forwards to that port. The user just listens on the port inside the sandbox
    (bound to 0.0.0.0) — no in-sandbox reverse proxy, no config, and crucially no pre-registration of ports. So the hostname-encoded approach is already fully dynamic; there's no per-port listener setup and no friction when a
    sandbox opens a new port. GitHub Codespaces (<codespace>-<port>.app.github.dev) works the same way.

    Docs: https://e2b.dev/docs/sandbox/internet-access

    The one thing we can't copy from E2B is the hyphen. Their sandbox IDs are constrained random strings, so <port>-<id> never collides. Our actor IDs are arbitrary DNS-1123 labels (80, 80-foo, … are all valid), which is
    exactly the ambiguity Tim Hockin (@thockin) flagged. That's why I'd switch to the dot-separated label you both suggested — port-<port>.<actor>.actors.resources.substrate.ate.dev — where the . boundary makes it unambiguous regardless of
    the actor ID. So E2B actually supports the design direction; we just need a separator the actor ID can't contain.

  8. thockin commented on Jul 7, 2026

    @thockin
    Collaborator

    (note: I edited the last comment to wrap <stuff in angle brackets> with backquotes - github allows naked HTML, apparently.


    Does it blink?
  9. thockin commented on Jul 7, 2026

    @thockin
    Collaborator

    The general approach seems OK, though I am a little worried that we end up with things like port-<p>.foo-<f>.bar-<b>.whatever-<w>.<name>.<atespace>.actors.resources.substrate.ate.dev where the whole prefix is a pseudo-map. This would also suggest that reordering the metadata would be equivalent but not equal. Maybe we need to mandate that metadata segments are sorted lexicographically (LC_SORT=C)?

    This would make http://port-99.foo.bar.actors.resources.substrate.ate.dev unambiguous but how about if I don't spec a port? What port does http://foo.bar.actors.resources.substrate.ate.dev mean? Does it change if I use https?

  10. bowei commented on Jul 17, 2026

    @bowei
    Collaborator

    This was pointed out in a side conversation:

    The current setup goes through Kubernetes Serivce and this does impose a limit on the number of different ports that could be allocated. We technically can put a quite a few Ports on a Service, but there is some limit way less than 65k.

    Maybe we should have fixed the all ports thing in K8s back then...

  11. thockin commented on Jul 19, 2026

    @thockin
    Collaborator

    I thought all the service does is 443/80 (for now)? Eventually TCP will be a problem...

  12. bowei commented on Jul 19, 2026

    @bowei
    Collaborator

    Clarify my comment -- it was to consider IF we wanted to support arbitrary numbers of ports and especially if we want to allow the user not have to declare ports apriori, the Kubernetes limitation comes into play.

  13. EItanya commented on Jul 24, 2026

    @EItanya
    Collaborator

    Given #445 and #484, I'm more than a little worried about relying on DNS for this feature.

    However, I do think this is a pretty large limitation and might be worth adding to M2 if we think we can fit it in

  14. added
    kind/feature
    on Aug 12, 2026
  15. bowei commented on Aug 24, 2026

    @bowei
    Collaborator

    This has been added via the CONNECT support. I am going to mark this as done, please open with a new issue for additional feature requests around multi-port support.

  16. EItanya commented on Aug 24, 2026

    @EItanya
    Collaborator

    I agree that this should be closed, should we create a follow-up to remove the single port implementation as clean-up?

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

Metadata

Metadata

Labels

area/networkkind/feature

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions