fix(interactive): pin PORT env var so code-server binds to the correct port#3450
Merged
Merged
Conversation
af717e9 to
fd83ca0
Compare
pingsutw
approved these changes
Jul 7, 2026
…t port
code-server reads the PORT environment variable as one of its bind-address
sources. When a pod/image sets PORT (common in Kubernetes), it overrode the
explicit --bind-addr flag and code-server bound to the wrong port.
Pass env={"PORT": str(self.port)} to the code-server subprocess so the
inherited PORT can't override --bind-addr. execute_command now accepts an
optional env dict that is merged on top of os.environ.
Signed-off-by: Jeev B <jeevb@users.noreply.github.com>
fd83ca0 to
46a879e
Compare
jeevb
added a commit
to flyteorg/flyte-sdk
that referenced
this pull request
Jul 7, 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>
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:{self.port}.Root cause
code-serverreads thePORTenvironment variable as one of its bind-address sources.execute_commandlaunches the subprocess viasubprocess.Popen(cmd, shell=True, ...), which 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 toPopen(..., env=...).vscodedecorator passesenv={"PORT": str(self.port)}to the code-server subprocess, pinningPORTso an inherited value can't override--bind-addr.Tests
test_vscode_passes_port_env_to_child_process— asserts the child process receivesenv={"PORT": "1234"}even when the surrounding environment hasPORT=9999.test_execute_command_passes_env_to_subprocess— asserts the override reachesPopenwhile other inherited vars survive.All 19 interactive unit tests pass.