Skip to content

fix(proxy): route custom ports through Rocklet instead of direct connect#1093

Open
alibabarock wants to merge 1 commit into
alibaba:masterfrom
alibabarock:fix/proxy-custom-port
Open

fix(proxy): route custom ports through Rocklet instead of direct connect#1093
alibabarock wants to merge 1 commit into
alibaba:masterfrom
alibabarock:fix/proxy-custom-port

Conversation

@alibabarock

Copy link
Copy Markdown

Problem

When users specify a custom port (not the default 8080) in HTTP or WebSocket proxy requests via Path/Header/Query parameters, the proxy attempts to connect directly to host_ip:{custom_port}. This fails because arbitrary container ports are not mapped to the host network.

Root Cause

In sandbox_proxy_service.py:

  • http_proxy(): When a custom port is specified, it constructs target_url = f"http://{host_ip}:{port}/..." directly
  • get_sandbox_websocket_url(): Same issue for WebSocket connections

However, only the default SERVER port (8080) is mapped from container to host. Custom ports like 9000, 3000 exist inside the container but are not accessible via host_ip:9000 from outside.

Solution

1. Add proxy endpoints to Rocklet (rock/rocklet/local_api.py)

  • /proxy/{port}/{path} for HTTP requests
  • /proxy/{port}/{path} for WebSocket connections

These endpoints run inside the container on Port.PROXY (22555) and can access localhost:{custom_port} reliably.

2. Modify sandbox_proxy_service.py to route custom ports through Rocklet

  • When port is None or 8080: use direct connection (backward compatible)
  • When port is custom (e.g. 9000): route through {rocklet_port}/proxy/{port}/{path}

3. Add tests

Comprehensive tests for routing logic in tests/unit/sandbox/test_proxy_custom_port_routing.py.

Impact

Users can now expose services running on arbitrary ports inside sandboxes to external clients, not just the default 8080 port. This enables scenarios like running multiple services on different ports within a single sandbox.

Testing

  • Verified routing logic with mock tests
  • Tested with actual sandbox on vpc-sg-a cluster
  • Default port (8080) behavior unchanged (backward compatible)
  • Custom ports (9000, 3000, etc.) now route through Rocklet successfully

fixes #1092

@CLAassistant

CLAassistant commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alibabarock alibabarock force-pushed the fix/proxy-custom-port branch from 898e21b to 75005ea Compare June 11, 2026 10:26
Problem:
When users specify a custom port (not 8080) in HTTP/WebSocket proxy requests,
the proxy attempts to connect directly to host_ip:{custom_port}. This fails
because arbitrary container ports are not mapped to the host network.

Root Cause:
- sandbox_proxy_service.http_proxy() line 939-946
- sandbox_proxy_service.get_sandbox_websocket_url() line 757-762

Both methods construct URLs like http://{host_ip}:{custom_port}/... directly,
but only the default SERVER port (8080) is mapped from container to host.

Solution:
1. Add proxy endpoints to Rocklet (local_api.py):
   - /proxy/{port}/{path} for HTTP
   - /proxy/{port}/{path} for WebSocket

   These endpoints run inside the container on Port.PROXY (22555) and can
   access localhost:{custom_port} reliably.

2. Modify sandbox_proxy_service.py to route custom ports through Rocklet:
   - When port is None or 8080: use direct connection (backward compatible)
   - When port is custom (e.g. 9000): route through {rocklet_port}/proxy/{port}/{path}

3. Add comprehensive tests for routing logic

Impact:
Users can now expose services running on arbitrary ports inside sandboxes
to external clients, not just the default 8080 port.

fixes alibaba#1092
@alibabarock alibabarock force-pushed the fix/proxy-custom-port branch from 75005ea to 73a62f3 Compare June 11, 2026 11:12
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.

Proxy: Custom port routing fails when connecting directly to host_ip:port

2 participants