Compare commits

...

3 commits

Author SHA1 Message Date
Ashish
248469544f
Merge 67808c2e4a into 25d7ae8374 2025-09-09 14:29:55 +08:00
Ashish
67808c2e4a
Merge pull request #1 from alahane-techtel/alahane-techtel-patch-1/NamedPipeCleanupRaceCondition
Fixed race condition on Named pipe dispose/disconnect
2025-07-07 17:04:39 +10:00
Ashish
d608026d17
Fixed race condition on Named pipe dispose/disconnect 2025-07-04 23:12:05 +10:00

View file

@ -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();
}
} }
} }
} }