Add configurable start port for Jupyter kernels and servers #17051
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.
Overview
This PR adds a new configuration setting that allows users to configure the starting port number used when launching Jupyter kernels and servers. This addresses the need for users in corporate environments, restricted networks, or those running multiple VS Code instances to control which ports the extension uses.
Closes #10765
Problem
Previously, the Jupyter extension hardcoded the starting port to 9000 for both:
This caused issues for users who:
Solution
Added a new VS Code setting:
jupyter.kernels.portRange.startPortConfiguration:
number9000(maintains backward compatibility)1024-65535(enforced by VS Code validation)machine(applies system-wide, can be overridden per workspace)Usage:
{ "jupyter.kernels.portRange.startPort": 10000 }Implementation Details
For Raw Kernels
Modified
KernelLauncherto dynamically read the configured start port and use it when allocating the 5 required ZeroMQ ports. The implementation:For Jupyter Servers
Modified
JupyterServerStarterto pass--port=<configured_port>to the Jupyter server command line when a non-default port is configured. When using the default port (9000), Jupyter uses its own port selection mechanism to maintain backward compatibility.Port Allocation Behavior
Testing
Added comprehensive unit tests:
Backward Compatibility
This change is fully backward compatible:
Code Quality
Use Cases
Corporate Environment:
{ "jupyter.kernels.portRange.startPort": 50000 // Use allowed port range }Multiple VS Code Instances:
Firewall Configuration:
{ "jupyter.kernels.portRange.startPort": 12000 // Specific allowed range }Files Changed
package.json- Added configuration setting with validationpackage.nls.json- Added localized descriptionsrc/platform/common/types.ts- Added property to IJupyterSettings interfacesrc/platform/common/configSettings.ts- Added property initializationsrc/kernels/raw/launcher/kernelLauncher.node.ts- Updated port allocation logicsrc/kernels/jupyter/launcher/jupyterServerStarter.node.ts- Added port argument generationsrc/kernels/raw/launcher/kernelLauncher.unit.test.ts- Added test coverageSecurity Considerations
Original prompt
Fixes #16810
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.