From 2b356fac492ed6a260e2f2a53eb40f976eb00b1e Mon Sep 17 00:00:00 2001 From: bajankristof Date: Wed, 19 Jun 2024 10:30:23 +0200 Subject: [PATCH 1/2] fix: resolve possible race condition in FFMPEG::Timeout --- lib/ffmpeg/timeout.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ffmpeg/timeout.rb b/lib/ffmpeg/timeout.rb index 65d9182..0e6f125 100644 --- a/lib/ffmpeg/timeout.rb +++ b/lib/ffmpeg/timeout.rb @@ -11,16 +11,21 @@ def self.start(duration, message = nil) end def pause - @paused = true + @mutex.synchronize { @paused = true } + nil end def resume - @paused = false - tick + @mutex.synchronize do + @last_tick = Time.now + @paused = false + nil + end end def tick - @last_tick = Time.now + @mutex.synchronize { @last_tick = Time.now } + nil end def cancel @@ -33,6 +38,7 @@ def cancel private def initialize(duration, message = nil) + @mutex = Mutex.new @duration = duration @message = message @@ -43,7 +49,7 @@ def initialize(duration, message = nil) end def loop - sleep 0.1 while @paused || Time.now - @last_tick <= @duration + sleep 0.1 while @mutex.synchronize { @paused || Time.now - @last_tick <= @duration } @current_thread.raise(::Timeout::Error, @message || self.class.name) end From 73598e5c5e03b216bb97e9c876a098d91646a4f9 Mon Sep 17 00:00:00 2001 From: bajankristof Date: Wed, 19 Jun 2024 10:32:52 +0200 Subject: [PATCH 2/2] chore: update version to 6.0.3 and document changes --- CHANGELOG | 5 +++++ lib/ffmpeg/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index ba9b82d..046ce83 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +== 6.0.2 2024-06-19 + +Fixes: +* Fixed a possible race condition that would cause the transcoder to time out even if the transcoder was still running + == 6.0.2 2024-06-18 Fixes: diff --git a/lib/ffmpeg/version.rb b/lib/ffmpeg/version.rb index ffb5345..1288713 100644 --- a/lib/ffmpeg/version.rb +++ b/lib/ffmpeg/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module FFMPEG - VERSION = '6.0.2' + VERSION = '6.0.3' end