mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +00:00
Merge pull request #1 from alahane-techtel/alahane-techtel-patch-1/NamedPipeCleanupRaceCondition
Fixed race condition on Named pipe dispose/disconnect
This commit is contained in:
commit
67808c2e4a
1 changed files with 14 additions and 4 deletions
|
|
@ -31,9 +31,13 @@ namespace FFMpegCore.Arguments
|
||||||
public void Post()
|
public void Post()
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
||||||
|
lock(Pipe)
|
||||||
|
{
|
||||||
|
|
||||||
Pipe?.Dispose();
|
Pipe?.Dispose();
|
||||||
Pipe = null!;
|
Pipe = null!;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task During(CancellationToken cancellationToken = default)
|
public async Task During(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|
@ -48,12 +52,18 @@ namespace FFMpegCore.Arguments
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
||||||
|
lock (Pipe ?? new object())
|
||||||
|
//if Pipe is null, then the lock doesnt matter,
|
||||||
|
//Because the next code will not execute anyways.
|
||||||
|
//so we can use a new object
|
||||||
|
{
|
||||||
if (Pipe is { IsConnected: true })
|
if (Pipe is { IsConnected: true })
|
||||||
{
|
{
|
||||||
Pipe.Disconnect();
|
Pipe.Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract Task ProcessDataAsync(CancellationToken token);
|
protected abstract Task ProcessDataAsync(CancellationToken token);
|
||||||
public abstract string Text { get; }
|
public abstract string Text { get; }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue