Skip to content

Fix breakpoint setting deadlock #1112

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEven
{
string reason = "changed";

if (_debugStateService.SetBreakpointInProgress)
if (_debugStateService.IsSetBreakpointInProgress)
{
// Don't send breakpoint update notifications when setting
// breakpoints on behalf of the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerShell.EditorServices.Utility;

namespace Microsoft.PowerShell.EditorServices.Services
{
internal class DebugStateService
{
private readonly SemaphoreSlim _setBreakpointInProgressHandle = AsyncUtils.CreateSimpleLockingSemaphore();

internal bool NoDebug { get; set; }

internal string Arguments { get; set; }
Expand All @@ -25,8 +31,20 @@ internal class DebugStateService

internal bool IsInteractiveDebugSession { get; set; }

internal bool SetBreakpointInProgress { get; set; }
// If the CurrentCount is equal to zero, then we have some thread using the handle.
internal bool IsSetBreakpointInProgress => _setBreakpointInProgressHandle.CurrentCount == 0;

internal bool IsUsingTempIntegratedConsole { get; set; }

internal void ReleaseSetBreakpointHandle()
{
_setBreakpointInProgressHandle.Release();
}

internal async Task WaitForSetBreakpointHandleAsync()
{
await _setBreakpointInProgressHandle.WaitAsync()
.ConfigureAwait(continueOnCapturedContext: false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<SetFunctionBreakpointsResponse> Handle(SetFunctionBreakpointsA
CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
if (!_debugStateService.NoDebug)
{
_debugStateService.SetBreakpointInProgress = true;
await _debugStateService.WaitForSetBreakpointHandleAsync();

try
{
Expand All @@ -63,7 +63,7 @@ await _debugService.SetCommandBreakpointsAsync(
}
finally
{
_debugStateService.SetBreakpointInProgress = false;
_debugStateService.ReleaseSetBreakpointHandle();
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ public async Task<SetBreakpointsResponse> Handle(SetBreakpointsArguments request
BreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
if (!_debugStateService.NoDebug)
{
_debugStateService.SetBreakpointInProgress = true;
await _debugStateService.WaitForSetBreakpointHandleAsync();

try
{
Expand All @@ -212,7 +212,7 @@ await _debugService.SetLineBreakpointsAsync(
}
finally
{
_debugStateService.SetBreakpointInProgress = false;
_debugStateService.ReleaseSetBreakpointHandle();
}
}

Expand Down