mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +00:00
Merge pull request #571 from techtel-pstevens/main
Fixed race condition on Named pipe dispose/disconnect
This commit is contained in:
commit
cf775ae7a9
1 changed files with 18 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ namespace FFMpegCore.Arguments;
|
||||||
public abstract class PipeArgument
|
public abstract class PipeArgument
|
||||||
{
|
{
|
||||||
private readonly PipeDirection _direction;
|
private readonly PipeDirection _direction;
|
||||||
|
private readonly object _pipeLock = new();
|
||||||
|
|
||||||
protected PipeArgument(PipeDirection direction)
|
protected PipeArgument(PipeDirection direction)
|
||||||
{
|
{
|
||||||
|
|
@ -21,6 +22,8 @@ public abstract class PipeArgument
|
||||||
public abstract string Text { get; }
|
public abstract string Text { get; }
|
||||||
|
|
||||||
public void Pre()
|
public void Pre()
|
||||||
|
{
|
||||||
|
lock (_pipeLock)
|
||||||
{
|
{
|
||||||
if (Pipe != null)
|
if (Pipe != null)
|
||||||
{
|
{
|
||||||
|
|
@ -29,13 +32,17 @@ public abstract class PipeArgument
|
||||||
|
|
||||||
Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
|
Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Post()
|
public void Post()
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
||||||
|
lock (_pipeLock)
|
||||||
|
{
|
||||||
Pipe?.Dispose();
|
Pipe?.Dispose();
|
||||||
Pipe = null!;
|
Pipe = null!;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task During(CancellationToken cancellationToken = default)
|
public async Task During(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|
@ -50,12 +57,15 @@ public abstract class PipeArgument
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
||||||
|
lock (_pipeLock)
|
||||||
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue