Skip to content

fix: blocking on async in ProcessExit handler and DedicatedThreadExecutor #4854

@thomhurst

Description

@thomhurst

Description

Two locations in the core engine synchronously block on async operations, violating the project's "NEVER block on async" principle.

Location 1: EngineCancellationToken.cs (Line 87)

Task.Delay(TimeSpan.FromMilliseconds(500)).GetAwaiter().GetResult();

This is in the ProcessExit event handler, which runs on a background thread with limited time (~3 seconds on Windows). Blocking on async here is a deadlock risk and can prevent After hooks from completing.

Location 2: DedicatedThreadExecutor.cs (Line 365)

waitTask.GetAwaiter().GetResult();

Synchronous blocking on an async task in a dedicated thread executor. Although the comment suggests it's safe, this blocks the thread unnecessarily and prevents responsive message pump processing.

Suggested Fix

Location 1: Register async callbacks using CancellationToken.Register() instead of blocking.

Location 2: Return a ValueTask that awaits the task: return new ValueTask(waitTask);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions