Skip to content

Fix SGLANG_GRPC_PORT overflow for high --port values#29517

Open
ajinkyajawale14499 wants to merge 3 commits into
sgl-project:mainfrom
ajinkyajawale14499:fix/grpc-port-overflow
Open

Fix SGLANG_GRPC_PORT overflow for high --port values#29517
ajinkyajawale14499 wants to merge 3 commits into
sgl-project:mainfrom
ajinkyajawale14499:fix/grpc-port-overflow

Conversation

@ajinkyajawale14499

@ajinkyajawale14499 ajinkyajawale14499 commented Jun 27, 2026

Copy link
Copy Markdown

Motivation

Closes #29416. When --port is greater than 55535, launching the server crashes with ValueError: SGLANG_GRPC_PORT (...) must be between 1 and 65535, even though the user never set SGLANG_GRPC_PORT. The reported command used --port 65438.

The cause is in ServerArgs: when SGLANG_GRPC_PORT is unset, grpc_port is derived as port + 10000, and the following range check then rejects anything above 65535.

Modifications

  • python/sglang/srt/server_args.py: when deriving grpc_port from --port, keep port + 10000, but fall back to port - 10000 when that would exceed 65535. port + 10000 > 65535 implies port > 55535, so port - 10000 > 45535, which stays in range and still differs from --port. An explicitly set SGLANG_GRPC_PORT is left untouched and still validated by the existing range check.
  • test/registered/unit/server_args/test_server_args.py: add TestGrpcPortDerivation covering the high-port case (no longer raises, stays in range, differs from --port) and the normal case (port + 10000).

Accuracy Tests

N/A. This is an argument-parsing change and does not affect model output.

Speed Tests and Profiling

N/A.

Checklist

  • Format your code according to the pre-commit guide (isort / ruff / black / codespell pass).
  • Add unit tests (CPU, base-a-test-cpu).
  • Update documentation. N/A.
  • Provide accuracy and speed benchmark results. N/A.
  • Follow the SGLang code style guidance.

The derivation was verified locally across several --port values; the ServerArgs construction test runs in CPU CI (developed on Apple Silicon, so I couldn't run the GPU suite locally).


CI States

Latest PR Test (Base): ❌ Run #28294831452
Latest PR Test (Extra): ❌ Run #28294831374

When SGLANG_GRPC_PORT is unset, grpc_port was derived as port + 10000, which
exceeds 65535 and raised ValueError for any --port > 55535. Fall back to
port - 10000 in that case so a valid --port no longer crashes. Adds unit tests.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the gRPC port derivation logic to prevent port overflow when a high port is configured. If the derived port (port + 10000) exceeds 65535, it falls back to port - 10000. Unit tests have been added to verify this behavior. The reviewer suggested simplifying the condition self.port + 10000 <= 65535 to self.port <= 55535 for better readability.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/server_args.py
ajinkyajawale14499 and others added 2 commits June 27, 2026 16:28
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

[Bug] SGLANG_GRPC_PORT may exceed beyond 65535

1 participant