mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
Fixed race condition on Named pipe dispose/disconnect
This commit is contained in:
parent
37973c3daf
commit
d608026d17
1 changed files with 14 additions and 4 deletions
|
|
@ -31,8 +31,12 @@ namespace FFMpegCore.Arguments
|
||||||
public void Post()
|
public void Post()
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
||||||
Pipe?.Dispose();
|
lock(Pipe)
|
||||||
Pipe = null!;
|
{
|
||||||
|
|
||||||
|
Pipe?.Dispose();
|
||||||
|
Pipe = null!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task During(CancellationToken cancellationToken = default)
|
public async Task During(CancellationToken cancellationToken = default)
|
||||||
|
|
@ -48,9 +52,15 @@ namespace FFMpegCore.Arguments
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
||||||
if (Pipe is { IsConnected: true })
|
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
|
||||||
{
|
{
|
||||||
Pipe.Disconnect();
|
if (Pipe is { IsConnected: true })
|
||||||
|
{
|
||||||
|
Pipe.Disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue