Skip to content

Bug: Port sharing fails for ports outside 4-digit range in multi-agent workspaces #22267

@VitorRamos

Description

@VitorRamos

When using workspace port sharing (CODER_WILDCARD_ACCESS_URL) in workspaces with multiple agents, accessing ports outside the 4-digit range (1000-9999) fails with the error:

port specified with no agent, but multiple agents exist in the workspace

This affects common ports like:

  • Low ports: 80, 443, 22 etc. (1-999)
  • High ports: 10000+, including 12000, 30000, etc. (10000-65535)

Steps to Reproduce

  1. Create a workspace with multiple agents (e.g., devcontainer setup)
  2. Start a service on a port outside 1000-9999 range:
    python -m http.server 12000
  3. Access the port via subdomain URL (e.g., https://12000--agent--workspace--user.coder.example.com)

Expected: Port forwards successfully to the specified agent
Actual: Error - "500 - Internal Server Error"

Coderd Logs

coderd.workspaceapps: workspace app auth server error: get app details from database
    request_id=8eea5ccd-c355-43de-ba1c-91d1c726bcd8
    username_or_id=username
    workspace_and_agent=""
    workspace_name_or_id=mx
    agent_name_or_id=""
    app_name_or_port=12000
    hostname_prefix="" ...
    error= port specified with no agent, but multiple agents exist in the workspace:
        github.com/coder/coder/v2/coderd/workspaceapps.Request.getDatabase
            /home/runner/work/coder/coder/coderd/workspaceapps/request.go:327

Metadata

Metadata

Assignees

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