Repository navigation
fix(debug): pin PORT env var so code-server binds to the correct port - #1286
Merged
Merged
Conversation
code-server also reads the PORT env var when resolving its bind address.
An inherited PORT (e.g. injected by Kubernetes) would override the explicit
--bind-addr flag, so pin PORT to VSCODE_PORT for the code-server subprocess.
- execute_command now accepts an optional env dict, merged on top of
os.environ and passed to create_subprocess_shell.
- _start_vscode_server passes env={"PORT": str(VSCODE_PORT)} and uses the
VSCODE_PORT constant for --bind-addr.
- Collapse the erroneous double asyncio.run in the child-process target to a
single call while threading env through.
Ports flytekit PR #3450 to the async flyte-sdk debug helpers.
Signed-off-by: Jeev B <jeevb@users.noreply.github.com>
The multiprocessing target was a lambda, which is not picklable under the spawn (macOS default) and forkserver start methods. Python 3.14 makes forkserver the default on Linux, so child_process.start() would raise PicklingError and the code-server debug feature would fail in-container. - Hoist the target to a module-level _run_code_server function. - Add a regression test that exercises _start_vscode_server, asserting the child process pins PORT to VSCODE_PORT and that the target is picklable (guards against reintroducing a lambda). Addresses code-review findings on PR branch. Signed-off-by: Jeev B <jeevb@users.noreply.github.com>
jeevb
force-pushed
the
jeev/fix-code-server-bind-port-override
branch
from
July 7, 2026 20:17
cdd188b to
739c9b3
Compare
jeevb
enabled auto-merge (squash)
July 7, 2026 20:19
pingsutw
approved these changes
Jul 7, 2026
samhita-alla
pushed a commit
that referenced
this pull request
Jul 15, 2026
…#1286) ## Problem When the pod/image has a `PORT` environment variable set (common in Kubernetes), the `code-server` subprocess binds to the wrong port despite being launched with `--bind-addr 0.0.0.0:{VSCODE_PORT}`. ## Root cause `code-server` reads the `PORT` environment variable as one of its bind-address sources. The subprocess inherits the parent process's full environment, so an inherited `PORT` overrides the explicit `--bind-addr` flag. ## Fix - `execute_command` now accepts an optional `env` dict, merged on top of `os.environ` (preserving other inherited vars) and passed to `asyncio.create_subprocess_shell(..., env=...)`. - `_start_vscode_server` passes `env={"PORT": str(VSCODE_PORT)}` to the code-server subprocess, pinning `PORT` so an inherited value can't override `--bind-addr`. The hardcoded `6060` is also replaced with the existing `VSCODE_PORT` constant for consistency. This ports flytekit PR flyteorg/flytekit#3450 to the async flyte-sdk debug helpers. ## Additional fix (from code review) The `multiprocessing` target was a lambda, which is **not picklable** under the `spawn` (macOS default) and `forkserver` start methods. Python 3.14 makes `forkserver` the default on Linux (POSIX), so `child_process.start()` would raise `PicklingError` and the code-server debug feature would fail in-container. The target is hoisted to a module-level `_run_code_server` function. (This also collapses a pre-existing double-`asyncio.run` bug in the lambda body.) ## Tests - `test_execute_command_passes_env_to_subprocess` — asserts the override reaches `create_subprocess_shell` while other inherited vars survive. - `test_execute_command_without_env_inherits_process_env` — asserts `env=None` (inherit parent) when no override is given. - `test_start_vscode_server_pins_port_env_with_picklable_target` — drives `_start_vscode_server` and asserts the child process pins `PORT` to `VSCODE_PORT`, the cmd uses `--bind-addr 0.0.0.0:6060`, and the target is picklable (guards against reintroducing a lambda). All 23 tests in `tests/flyte/test_debug.py` pass; lint and format clean. --------- Signed-off-by: Jeev B <jeevb@users.noreply.github.com> Signed-off-by: Samhita Alla <aallasamhita@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the pod/image has a
PORTenvironment variable set (common in Kubernetes), thecode-serversubprocess binds to the wrong port despite being launched with--bind-addr 0.0.0.0:{VSCODE_PORT}.Root cause
code-serverreads thePORTenvironment variable as one of its bind-address sources. The subprocess inherits the parent process's full environment, so an inheritedPORToverrides the explicit--bind-addrflag.Fix
execute_commandnow accepts an optionalenvdict, merged on top ofos.environ(preserving other inherited vars) and passed toasyncio.create_subprocess_shell(..., env=...)._start_vscode_serverpassesenv={"PORT": str(VSCODE_PORT)}to the code-server subprocess, pinningPORTso an inherited value can't override--bind-addr. The hardcoded6060is also replaced with the existingVSCODE_PORTconstant for consistency.This ports flytekit PR flyteorg/flytekit#3450 to the async flyte-sdk debug helpers.
Additional fix (from code review)
The
multiprocessingtarget was a lambda, which is not picklable under thespawn(macOS default) andforkserverstart methods. Python 3.14 makesforkserverthe default on Linux (POSIX), sochild_process.start()would raisePicklingErrorand the code-server debug feature would fail in-container. The target is hoisted to a module-level_run_code_serverfunction. (This also collapses a pre-existing double-asyncio.runbug in the lambda body.)Tests
test_execute_command_passes_env_to_subprocess— asserts the override reachescreate_subprocess_shellwhile other inherited vars survive.test_execute_command_without_env_inherits_process_env— assertsenv=None(inherit parent) when no override is given.test_start_vscode_server_pins_port_env_with_picklable_target— drives_start_vscode_serverand asserts the child process pinsPORTtoVSCODE_PORT, the cmd uses--bind-addr 0.0.0.0:6060, and the target is picklable (guards against reintroducing a lambda).All 23 tests in
tests/flyte/test_debug.pypass; lint and format clean.