Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
Move dap setup to setup job step#4403
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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
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 |
|---|---|---|
| @@ -16,6 +16,7 @@ | ||
| using GitHub.Runner.Common; | ||
| using GitHub.Runner.Common.Util; | ||
| using GitHub.Runner.Sdk; | ||
| using GitHub.Runner.Worker.Dap; | ||
| using GitHub.Services.Common; | ||
| using Newtonsoft.Json; | ||
| using Pipelines = GitHub.DistributedTask.Pipelines; | ||
| @@ -50,6 +51,7 @@ public sealed class JobExtension : RunnerService, IJobExtension | ||
| private Task _diskSpaceCheckTask = null; | ||
| private CancellationTokenSource _serviceConnectivityCheckToken = new(); | ||
| private Task _serviceConnectivityCheckTask = null; | ||
| private IDapDebugger _dapDebugger; | ||
| // Download all required actions. | ||
| // Make sure all condition inputs are valid. | ||
| @@ -67,6 +69,7 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel | ||
| List<IStep> preJobSteps = new(); | ||
| List<IStep> jobSteps = new(); | ||
| var initSucceeded = false; | ||
| using (var register = jobContext.CancellationToken.Register(() => { context.CancelToken(); })) | ||
| { | ||
| try | ||
| @@ -481,6 +484,41 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel | ||
| Trace.Info($"Start checking service connectivity in background."); | ||
| _serviceConnectivityCheckTask = CheckServiceConnectivityAsync(context, _serviceConnectivityCheckToken.Token); | ||
| // Start the DAP debugger and wait for a client connection inside | ||
| // "Set up job" so the step stays in-progress while we wait. | ||
| if (jobContext.Global.Debugger?.Enabled == true) | ||
| { | ||
| Trace.Info("Debugger enabled — starting inside Set up job"); | ||
| context.Output("Starting debugger…"); | ||
| try | ||
| { | ||
| _dapDebugger = HostContext.GetService<IDapDebugger>(); | ||
| await _dapDebugger.StartAsync(jobContext); | ||
| context.Output("Waiting for debugger client to connect…"); | ||
| await _dapDebugger.WaitUntilReadyAsync(); | ||
| context.Output("Debugger connected."); | ||
| AddDebuggerConnectionTelemetry(jobContext, "Connected"); | ||
| } | ||
| catch (OperationCanceledException) when (jobContext.CancellationToken.IsCancellationRequested) | ||
| { | ||
| Trace.Info("Job was cancelled before debugger client connected."); | ||
| AddDebuggerConnectionTelemetry(jobContext, "Canceled"); | ||
| context.Error("Job was cancelled before debugger client connected."); | ||
| throw; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Trace.Error($"DAP debugger failed: {ex.Message}"); | ||
| AddDebuggerConnectionTelemetry(jobContext, $"Failed: {ex.GetType().Name}"); | ||
| context.Error("The debugger failed to start or no debugger client connected in time."); | ||
| throw; | ||
| } | ||
| } | ||
| initSucceeded = true; | ||
| return steps; | ||
| } | ||
| catch (OperationCanceledException ex) when (jobContext.CancellationToken.IsCancellationRequested) | ||
| @@ -501,12 +539,36 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel | ||
| } | ||
| finally | ||
| { | ||
| // If InitializeJob failed after the debugger was started, | ||
| // tear down the transport here since FinalizeJob won't run. | ||
| if (!initSucceeded && _dapDebugger != null) | ||
| { | ||
| try | ||
| { | ||
| await _dapDebugger.StopAsync(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Trace.Warning($"DAP debugger cleanup during failed init: {ex.Message}"); | ||
| } | ||
| _dapDebugger = null; | ||
| } | ||
| context.Debug("Finishing: Set up job"); | ||
| context.Complete(); | ||
| } | ||
| } | ||
| } | ||
| private static void AddDebuggerConnectionTelemetry(IExecutionContext jobContext, string result) | ||
| { | ||
| jobContext.Global.JobTelemetry.Add(new JobTelemetry | ||
| { | ||
| Type = JobTelemetryType.General, | ||
| Message = $"DebuggerConnectionResult: {result}" | ||
| }); | ||
| } | ||
| private string GetWorkflowReference(IDictionary<string, VariableValue> variables) | ||
| { | ||
| var reference = ""; | ||
| @@ -782,6 +844,34 @@ public async Task FinalizeJob(IExecutionContext jobContext, Pipelines.AgentJobRe | ||
| } | ||
| finally | ||
| { | ||
| // Pause for debugger inspection, then tear down the DAP session. | ||
| // OnJobCompletedAsync pauses first, then sends terminated/exited | ||
| // events and stops the transport. | ||
| if (_dapDebugger != null) | ||
rentziass marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| { | ||
| context.Output("Job completed — pausing for debugger inspection. Press continue to finish."); | ||
| try | ||
| { | ||
| await _dapDebugger.OnJobCompletedAsync(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Trace.Warning($"DAP debugger completion error: {ex.Message}"); | ||
| } | ||
| finally | ||
| { | ||
| try | ||
| { | ||
| await _dapDebugger.StopAsync(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Trace.Warning($"DAP debugger stop error: {ex.Message}"); | ||
| } | ||
| } | ||
| _dapDebugger = null; | ||
| } | ||
| context.Debug("Finishing: Complete job"); | ||
| context.Complete(); | ||
| } | ||
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
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we pass in the step level context instead of the
jobContext?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The debugger needs jobs cancellation, Global.Debugger and variable provider from the job context, plus I think it needs a context that outlives the setup step? This isn't new btw, it just moved into the step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
Globalobject is shared across all context (step + job).you were using jobcontext since the code in jobrunner.cs doesn't have a step context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also we hook up to jobcontext cancelation in the debugger, if we used the step context wouldn't that be completed when Setup job completes?