Skip to content

In PSScript and PSAdapter, if TryDequeue fails, we just return#1625

Closed
SteveL-MSFT wants to merge 4 commits into
PowerShell:mainfrom
SteveL-MSFT:trace-queue
Closed

In PSScript and PSAdapter, if TryDequeue fails, we just return#1625
SteveL-MSFT wants to merge 4 commits into
PowerShell:mainfrom
SteveL-MSFT:trace-queue

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

PR Summary

Something is causing a hang. According to the docs TryDequeue should only fail if empty, but perhaps there's some unknown interaction resulting in TryDequeue failing, but IsEmpty reports not, so change is to return if TryDequeue fails.

PR Context

Fix #1609

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR mitigates a potential hang in the PowerShellScript resource and the PowerShell adapter by avoiding an infinite loop when ConcurrentQueue.TryDequeue() unexpectedly returns false while IsEmpty indicates the queue is not empty (likely due to concurrency timing).

Changes:

  • Add an early-return guard in Write-TraceQueue() when TryDequeue() fails (PSScript resource).
  • Add the same early-return guard in Write-TraceQueue() for the PowerShell adapter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
resources/PSScript/psscript.ps1 Prevents Write-TraceQueue() from potentially looping forever if TryDequeue() fails despite IsEmpty being false.
adapters/powershell/psDscAdapter/powershell.resource.ps1 Applies the same protection to adapter-side trace draining to avoid hangs in adapter execution.

Comment thread resources/PSScript/psscript.ps1 Outdated
Comment thread adapters/powershell/psDscAdapter/powershell.resource.ps1 Outdated
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Abandoning this change, it's causing test failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dsc hangs up when used with task scheduler

2 participants