<#1286 fix(debug): pin PORT env var so code-server...
# flyte-github
a
#1286 fix(debug): pin PORT env var so code-server binds to the correct port Pull request opened by jeevb 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. flyteorg/flyte-sdk