Skip to content

Commit 4098d09

Browse files
committed
Add inter-process mutex to fix double inotify events and timing issues
1 parent 7cbd415 commit 4098d09

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Start-Autoconv.ps1

+12
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,17 @@ function Invoke-Ffmpeg {
435435
#endregion
436436

437437
#region main entry point
438+
[System.Threading.Mutex]$mutex = $null
439+
[boolean]$gotMutex = $false
438440
try {
439441
Parse-Config
440442
Examine-InputFile
441443
Select-Codecs
444+
$mutex = New-Object System.Threading.Mutex($false, "Global\$($File.Name)")
445+
$gotMutex = $mutex.WaitOne(60 * 1000) # 1 minute to let other process get started
446+
if (-not $gotMutex) {
447+
Write-Debug "[$LOG_TAG]Failed to get mutex. Maybe inotify double-fired?"
448+
}
442449
Invoke-Ffmpeg
443450
}
444451
catch {
@@ -450,5 +457,10 @@ catch {
450457
Write-Error -Message $_
451458
}
452459
}
460+
finally {
461+
if ($mutex -ne $null -and $gotMutex) {
462+
$mutex.ReleaseMutex()
463+
}
464+
}
453465
Write-Output "[$LOG_TAG]Complete."
454466
#endregion

0 commit comments

Comments
 (0)