Skip to content

Commit

Permalink
Fix #576 (Deadlock) (#611)
Browse files Browse the repository at this point in the history
Co-authored-by: Darren <darren@velogicfit.com>
  • Loading branch information
dbruning and Darren committed Sep 15, 2023
1 parent c7fe5ab commit 6cae62e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions Unosquare.FFME/Commands/CommandManager.Direct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ private bool IsCloseInterruptPending
/// <returns>The awaitable task.</returns>
private Task<bool> ExecuteDirectCommand(DirectCommandType command, Func<bool> commandDeleagte)
{
// 2021-12-16 Moved this out of the lock, to avoid deadlock (#576)
if (IsDisposed || IsDisposing)
{
this.LogWarning(Aspects.EngineCommand, $"Direct Command '{command}' not accepted. Commanding is disposed or a command is pending completion.");
return Task.FromResult(false);
}

lock (SyncLock)
{
// Check the basic conditions for a direct command to execute
if (IsDisposed || IsDisposing)
{
this.LogWarning(Aspects.EngineCommand, $"Direct Command '{command}' not accepted. Commanding is disposed or a command is pending completion.");
return Task.FromResult(false);
}

if (IsDirectCommandPending || command == DirectCommandType.None)
{
this.LogWarning(Aspects.EngineCommand, $"Direct Command '{command}' not accepted. {PendingDirectCommand} command is pending completion.");
Expand Down
4 changes: 2 additions & 2 deletions Unosquare.FFME/Commands/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Unosquare.FFME.Commands
using System.Threading.Tasks;

/// <summary>
/// Provides the MediEngine with an API to execute media control commands.
/// Direct Commands execute immediately (Open, CLose, Change)
/// Provides the MediaEngine with an API to execute media control commands.
/// Direct Commands execute immediately (Open, Close, Change)
/// Priority Commands execute in the queue but before anything else and are exclusive (Play, Pause, Stop)
/// Seek commands are queued and replaced. These are processed in a deferred manner by this worker.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Unosquare.FFME/Primitives/WorkerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public Task<WorkerState> StartAsync()
/// <inheritdoc />
public Task<WorkerState> PauseAsync()
{
// 2021-12-16 Moved this outside of the sync block, to avoid deadlock (#576)
if (IsDisposed || IsDisposing)
return Task.FromResult(WorkerState);
lock (SyncLock)
{
if (IsDisposed || IsDisposing)
return Task.FromResult(WorkerState);

if (WorkerState != WorkerState.Running)
return Task.FromResult(WorkerState);

Expand Down

0 comments on commit 6cae62e

Please sign in to comment.