-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add WS bridge over DAP TCP server #4328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rentziass
wants to merge
8
commits into
main
Choose a base branch
from
rentziass/debugger-ws-bridge-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,272
−4
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21ba579
Add WS bridge over DAP TCP server
rentziass ac65885
fix windows
rentziass b569086
Update src/Runner.Worker/Dap/WebSocketDapBridge.cs
rentziass cfbedd5
feedback
rentziass 7783c98
feedback
rentziass ab2e854
Merge branch 'main' into rentziass/debugger-ws-bridge-fix
rentziass f7563d3
Merge branch 'main' into rentziass/debugger-ws-bridge-fix
rentziass 7eab609
PR feedback
rentziass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ public sealed class DapDebugger : RunnerService, IDapDebugger | |
|
|
||
| // Dev Tunnel relay host for remote debugging | ||
| private TunnelRelayTunnelHost _tunnelRelayHost; | ||
| private WebSocketDapBridge _webSocketBridge; | ||
|
|
||
| // Cancellation source for the connection loop, cancelled in StopAsync | ||
| // so AcceptTcpClientAsync unblocks cleanly without relying on listener disposal. | ||
|
|
@@ -74,6 +75,10 @@ public sealed class DapDebugger : RunnerService, IDapDebugger | |
| // When true, skip tunnel relay startup (unit tests only) | ||
| internal bool SkipTunnelRelay { get; set; } | ||
|
|
||
| // When true, skip the public websocket bridge and expose the raw DAP | ||
| // listener directly on the configured tunnel port (unit tests only). | ||
| internal bool SkipWebSocketBridge { get; set; } | ||
|
|
||
| // Synchronization for step execution | ||
| private TaskCompletionSource<DapCommand> _commandTcs; | ||
| private readonly object _stateLock = new object(); | ||
|
|
@@ -108,6 +113,7 @@ public sealed class DapDebugger : RunnerService, IDapDebugger | |
| _state == DapSessionState.Running; | ||
|
|
||
| internal DapSessionState State => _state; | ||
| internal int InternalDapPort => (_listener?.LocalEndpoint as IPEndPoint)?.Port ?? 0; | ||
|
|
||
| public override void Initialize(IHostContext hostContext) | ||
| { | ||
|
|
@@ -133,9 +139,21 @@ public async Task StartAsync(IExecutionContext jobContext) | |
| _jobContext = jobContext; | ||
| _readyTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
|
||
| _listener = new TcpListener(IPAddress.Loopback, debuggerConfig.Tunnel.Port); | ||
| var dapPort = SkipWebSocketBridge ? debuggerConfig.Tunnel.Port : 0; | ||
| _listener = new TcpListener(IPAddress.Loopback, dapPort); | ||
| _listener.Start(); | ||
| Trace.Info($"DAP debugger listening on {_listener.LocalEndpoint}"); | ||
| if (SkipWebSocketBridge) | ||
| { | ||
| Trace.Info($"DAP debugger listening on {_listener.LocalEndpoint}"); | ||
| } | ||
| else | ||
| { | ||
| Trace.Info($"Internal DAP debugger listening on {_listener.LocalEndpoint}"); | ||
| _webSocketBridge = new WebSocketDapBridge(); | ||
| _webSocketBridge.Initialize(HostContext); | ||
| _webSocketBridge.Configure(debuggerConfig.Tunnel.Port, InternalDapPort); | ||
| _webSocketBridge.Start(); | ||
| } | ||
|
|
||
| // Start Dev Tunnel relay so remote clients reach the local DAP port. | ||
| // The relay is torn down explicitly in StopAsync (after the DAP session | ||
|
|
@@ -274,6 +292,22 @@ public async Task StopAsync() | |
| _tunnelRelayHost = null; | ||
| } | ||
|
|
||
| if (_webSocketBridge != null) | ||
| { | ||
| Trace.Info("Stopping WebSocket DAP bridge"); | ||
| var shutdownTask = _webSocketBridge.ShutdownAsync(); | ||
| if (await Task.WhenAny(shutdownTask, Task.Delay(5_000)) != shutdownTask) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small thing, if the 5s timeout fires |
||
| { | ||
| Trace.Warning("WebSocket DAP bridge shutdown timed out after 5s"); | ||
| } | ||
| else | ||
| { | ||
| Trace.Info("WebSocket DAP bridge stopped"); | ||
| } | ||
|
|
||
| _webSocketBridge = null; | ||
| } | ||
|
|
||
| CleanupConnection(); | ||
|
|
||
| // Cancel the connection loop first so AcceptTcpClientAsync unblocks | ||
|
|
@@ -315,6 +349,7 @@ public async Task StopAsync() | |
| _connectionLoopTask = null; | ||
| _loopCts?.Dispose(); | ||
| _loopCts = null; | ||
| _webSocketBridge = null; | ||
| } | ||
|
|
||
| public async Task OnStepStartingAsync(IStep step) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.