From 52521694e834f78c718a59033f0e37939987a52f Mon Sep 17 00:00:00 2001 From: Vladimir Sumarov Date: Wed, 28 Oct 2026 17:45:36 -0700 Subject: [PATCH 1/2] Bound obs64 shutdown with a watchdog and free the exit pipe after ack obs64 teardown had no deadline, so a hang left it running after Desktop exited, holding CEF's cache lock and the exit pipe name the next session needs. A watchdog now terminates it on overrun, and the pipe is closed after the ack. Co-Authored-By: Claude Opus 5.5 --- obs-studio-server/CMakeLists.txt | 3 + obs-studio-server/source/main.cpp | 6 + obs-studio-server/source/nodeobs_api.cpp | 46 +++-- obs-studio-server/source/osn-output.cpp | 11 + obs-studio-server/source/osn-output.hpp | 5 + .../source/shutdown-watchdog.cpp | 136 +++++++++++++ .../source/shutdown-watchdog.hpp | 96 +++++++++ .../tests/test-shutdown-watchdog.cpp | 192 ++++++++++++++++++ 8 files changed, 479 insertions(+), 16 deletions(-) create mode 100644 obs-studio-server/source/shutdown-watchdog.cpp create mode 100644 obs-studio-server/source/shutdown-watchdog.hpp create mode 100644 obs-studio-server/tests/test-shutdown-watchdog.cpp diff --git a/obs-studio-server/CMakeLists.txt b/obs-studio-server/CMakeLists.txt index c83185322..eee6960df 100644 --- a/obs-studio-server/CMakeLists.txt +++ b/obs-studio-server/CMakeLists.txt @@ -334,6 +334,8 @@ SET(osn-server_SOURCES "${PROJECT_SOURCE_DIR}/source/osn-audio-bitrate.hpp" "${PROJECT_SOURCE_DIR}/source/osn-output.cpp" "${PROJECT_SOURCE_DIR}/source/osn-output.hpp" + "${PROJECT_SOURCE_DIR}/source/shutdown-watchdog.cpp" + "${PROJECT_SOURCE_DIR}/source/shutdown-watchdog.hpp" "${PROJECT_SOURCE_DIR}/source/osn-properties.cpp" "${PROJECT_SOURCE_DIR}/source/osn-properties.hpp" "${PROJECT_SOURCE_DIR}/source/osn-scene.cpp" @@ -669,6 +671,7 @@ if(BUILD_TESTING) "tests/test-nodeobs-enhanced-broadcasting-vod.cpp" "tests/test-osn-scene-relative-coordinates.cpp" "tests/test-osn-video-mix-lifecycle.cpp" + "tests/test-shutdown-watchdog.cpp" "tests/obs-setup.cpp" "tests/obs-setup.hpp" "tests/scoped-helpers.hpp" diff --git a/obs-studio-server/source/main.cpp b/obs-studio-server/source/main.cpp index 5df30e45c..c9ab0196b 100644 --- a/obs-studio-server/source/main.cpp +++ b/obs-studio-server/source/main.cpp @@ -70,6 +70,7 @@ #include "util-crashmanager.h" #include "shared.hpp" +#include "shutdown-watchdog.hpp" #ifndef OSN_VERSION #define OSN_VERSION "DEVMODE_VERSION" @@ -341,6 +342,7 @@ int main(int argc, char *argv[]) // before going further with shutdown. It needed for usecase where obs64 process stay alive and // continue streaming till user confirms exit in crash-handler. OBS_API::WaitCrashHandlerClose(waitBeforeClosing); + osn::ShutdownWatchdog::Instance().Arm("Prepare", osn::shutdown_budget::Prepare); #endif osn::Source::finalize_global_signals(); @@ -349,6 +351,10 @@ int main(int argc, char *argv[]) // Then, shutdown OBS OBS_API::destroyOBS_API(); +#ifdef WIN32 + // Skips exit-time work (DLL detach, static destructors) that can hang. + TerminateProcess(GetCurrentProcess(), 0); +#endif #ifdef __APPLE__ util::CrashManager::DeleteBriefCrashInfoFile(); if (override_std_fd) { diff --git a/obs-studio-server/source/nodeobs_api.cpp b/obs-studio-server/source/nodeobs_api.cpp index 70999e72d..f051bf06b 100644 --- a/obs-studio-server/source/nodeobs_api.cpp +++ b/obs-studio-server/source/nodeobs_api.cpp @@ -46,6 +46,7 @@ //to destroy cpu usage object #include "osn-global.hpp" +#include "shutdown-watchdog.hpp" #include @@ -1098,6 +1099,10 @@ void OBS_API::OBS_API_destroyOBS_API(void *data, const int64_t id, const std::ve osn::Source::finalize_global_signals(); /* END INJECT osn::Source::Manager */ destroyOBS_API(); +#ifdef _WIN32 + // The process keeps running after this call. + osn::ShutdownWatchdog::Instance().Disarm(); +#endif rval.push_back(ipc::value((uint64_t)ErrorCode::Ok)); AUTO_DEBUG; } @@ -1425,17 +1430,6 @@ BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo) return fPendingIO; } -VOID DisconnectAndReconnect(void) -{ - if (!DisconnectNamedPipe(Pipe.hPipeInst)) { - return; - } - - Pipe.fPendingIO = ConnectToNewClient(Pipe.hPipeInst, &(Pipe.oOverlap)); - - Pipe.dwState = Pipe.fPendingIO ? CONNECTING_STATE : READING_STATE; -} - bool prepareTerminationPipe() { LPCTSTR lpszPipename = TEXT("\\\\.\\pipe\\exit-slobs-crash-handler"); @@ -1479,7 +1473,6 @@ void acknowledgeTerminate() // We timeout, crash handler failed to send the shutdown acknowledge, // we move forward with the shutdown procedure crash_handler_exit = true; - CloseHandle(Pipe.hPipeInst); break; } } @@ -1500,7 +1493,6 @@ void acknowledgeTerminate() case READING_STATE: { if (!fSuccess || cbRet == 0) { crash_handler_exit = true; - DisconnectAndReconnect(); break; } Pipe.cbRead = cbRet; @@ -1530,12 +1522,17 @@ void acknowledgeTerminate() break; } crash_handler_exit = true; - DisconnectAndReconnect(); break; } } } } + + // Single exit: the pipe name is free again for the next session. + CloseHandle(Pipe.hPipeInst); + Pipe.hPipeInst = INVALID_HANDLE_VALUE; + CloseHandle(hEvents); + hEvents = NULL; } #else __APPLE__ void acknowledgeTerminate(void) @@ -1667,6 +1664,11 @@ void OBS_API::destroyOBS_API(void) DisableAudioDucking(false); } #endif + +#ifdef _WIN32 + osn::ShutdownWatchdog::Instance().Arm("Outputs", osn::shutdown_budget::OutputStep); + osn::ShutdownWatchdog::Instance().SetCap(osn::shutdown_budget::OutputCap); +#endif OBS_content::OBS_content_shutdownDisplays(); ScreenshotManager::GetInstance().Shutdown(); @@ -1768,16 +1770,28 @@ void OBS_API::destroyOBS_API(void) // Release all streaming ouputs osn::IStreaming::Manager::GetInstance().for_each([](osn::Streaming *streamingOutput) { - if (streamingOutput) + if (streamingOutput) { +#ifdef _WIN32 + osn::ShutdownWatchdog::Instance().Kick(osn::shutdown_budget::OutputStep); +#endif delete streamingOutput; + } }); // Release all recording ouputs osn::IFileOutput::Manager::GetInstance().for_each([](osn::FileOutput *fileOutput) { - if (fileOutput) + if (fileOutput) { +#ifdef _WIN32 + osn::ShutdownWatchdog::Instance().Kick(osn::shutdown_budget::OutputStep); +#endif delete fileOutput; + } }); +#ifdef _WIN32 + osn::ShutdownWatchdog::Instance().Arm("Teardown", osn::shutdown_budget::Teardown); +#endif + // Stop the cache worker before draining destruction: it can still own the // last reference to a removed source and enqueue its destruction later. // Both source-registry walks below connect/disconnect signals while holding diff --git a/obs-studio-server/source/osn-output.cpp b/obs-studio-server/source/osn-output.cpp index b8b60206d..8a09c9a6b 100644 --- a/obs-studio-server/source/osn-output.cpp +++ b/obs-studio-server/source/osn-output.cpp @@ -32,15 +32,23 @@ void osn::Output::InitOutput(obs_output_t *output) } signal_handler *sh = obs_output_get_signal_handler(output); + signal_handler_connect(sh, "stopping", osn::Output::OnStopping, this); signal_handler_connect(sh, "stop", osn::Output::OnStopped, this); ConnectSignals(); } +void osn::Output::OnStopping(void *data, calldata_t *) +{ + reinterpret_cast(data)->m_finalizeTracker.Begin(); +} + void osn::Output::OnStopped(void *data, calldata_t *) { osn::Output *context = reinterpret_cast(data); + context->m_finalizeTracker.End(); + // Before m_mtxOutputStop: DeleteOutput() holds that lock for up to 20s waiting // on m_cvStop, and nothing should queue behind it. context->OnOutputStopped(); @@ -92,8 +100,10 @@ void osn::Output::DeleteOutput() // into freed CallbackData/this would crash in signal_handler_signal. DisconnectSignals(); + // Release can block until the muxer finishes writing, so it still counts as finalizing. obs_output_release(m_output); m_output = nullptr; + m_finalizeTracker.End(); } void osn::OutputSignalCallback(void *data, calldata_t *params) @@ -136,6 +146,7 @@ void osn::Output::DisconnectSignals() signal_handler *handler = obs_output_get_signal_handler(m_output); if (handler) { + signal_handler_disconnect(handler, "stopping", osn::Output::OnStopping, this); signal_handler_disconnect(handler, "stop", osn::Output::OnStopped, this); for (auto *cd : m_signalCallbackData) signal_handler_disconnect(handler, cd->signal.c_str(), osn::OutputSignalCallback, cd); diff --git a/obs-studio-server/source/osn-output.hpp b/obs-studio-server/source/osn-output.hpp index 12ea14c8c..6e07b1b53 100644 --- a/obs-studio-server/source/osn-output.hpp +++ b/obs-studio-server/source/osn-output.hpp @@ -20,6 +20,8 @@ #include +#include "shutdown-watchdog.hpp" + #include #include #include @@ -85,8 +87,11 @@ class Output { // the CallbackData. Must run while m_output is still valid. void DisconnectSignals(); + static void OnStopping(void *data, calldata_t *params); static void OnStopped(void *data, calldata_t *params); + osn::FinalizeTracker m_finalizeTracker{osn::ShutdownWatchdog::Instance()}; + obs_video_info *m_canvas = nullptr; obs_output_t *m_output = nullptr; diff --git a/obs-studio-server/source/shutdown-watchdog.cpp b/obs-studio-server/source/shutdown-watchdog.cpp new file mode 100644 index 000000000..5bcb80648 --- /dev/null +++ b/obs-studio-server/source/shutdown-watchdog.cpp @@ -0,0 +1,136 @@ +#include "shutdown-watchdog.hpp" + +#include + +#include + +#ifdef _WIN32 +#include +#endif + +osn::ShutdownWatchdog::ShutdownWatchdog(NowFn now, ExpiredFn onExpired, std::chrono::milliseconds pollInterval) + : m_now(std::move(now)), m_onExpired(std::move(onExpired)), m_pollInterval(pollInterval) +{ +} + +osn::ShutdownWatchdog::~ShutdownWatchdog() +{ + { + std::lock_guard lock(m_mtx); + m_stop = true; + } + m_cv.notify_all(); + if (m_thread.joinable()) + m_thread.join(); +} + +#ifdef _WIN32 +namespace { +constexpr UINT WatchdogExitCode = 0x0B5D0001; + +void TerminateSelf(const std::string &stage, std::chrono::seconds exceeded) +{ + // The hung thread may hold the log mutex, so log from a helper and give up on it after 1 s. + auto logged = std::make_shared>(false); + std::thread([logged, stage, exceeded] { + blog(LOG_ERROR, "Shutdown watchdog: %s exceeded %lld s, terminating", stage.c_str(), static_cast(exceeded.count())); + *logged = true; + }).detach(); + + for (int i = 0; i < 100 && !*logged; i++) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + TerminateProcess(GetCurrentProcess(), WatchdogExitCode); +} +} // namespace + +#endif + +osn::ShutdownWatchdog &osn::ShutdownWatchdog::Instance() +{ +#ifdef _WIN32 + static ShutdownWatchdog *instance = new ShutdownWatchdog(&Clock::now, &TerminateSelf); +#else + // Never armed outside Windows. + static ShutdownWatchdog *instance = new ShutdownWatchdog(&Clock::now, [](const std::string &, std::chrono::seconds) {}); +#endif + return *instance; +} + +void osn::ShutdownWatchdog::Arm(const std::string &stage, std::chrono::seconds budget) +{ + { + std::lock_guard lock(m_mtx); + m_armed = true; + m_stage = stage; + m_budget = budget; + m_deadline = m_now() + budget; + m_cap.reset(); + if (!m_thread.joinable()) + m_thread = std::thread(&ShutdownWatchdog::Run, this); + } + m_cv.notify_all(); +} + +void osn::ShutdownWatchdog::Kick(std::chrono::seconds budget) +{ + std::lock_guard lock(m_mtx); + if (!m_armed) + return; + m_budget = budget; + m_deadline = m_now() + budget; +} + +void osn::ShutdownWatchdog::SetCap(std::chrono::seconds cap) +{ + std::lock_guard lock(m_mtx); + m_cap = Cap{m_now() + cap, cap}; +} + +void osn::ShutdownWatchdog::Disarm() +{ + std::lock_guard lock(m_mtx); + m_armed = false; +} + +void osn::ShutdownWatchdog::AddFinalizing(int delta) +{ + std::lock_guard lock(m_mtx); + m_finalizing += delta; + // Each output gets a fresh step once it finishes finalizing. + if (m_finalizing == 0 && delta < 0 && m_armed) + m_deadline = m_now() + m_budget; +} + +bool osn::ShutdownWatchdog::IsExpired(Clock::time_point now, std::chrono::seconds &exceeded) const +{ + if (m_cap && now >= m_cap->at) { + exceeded = m_cap->limit; + return true; + } + if (now < m_deadline) + return false; + if (m_cap && m_finalizing > 0) + return false; + exceeded = m_budget; + return true; +} + +void osn::ShutdownWatchdog::Run() +{ + std::unique_lock lock(m_mtx); + while (!m_stop) { + m_cv.wait_for(lock, m_pollInterval); + if (m_stop) + break; + std::chrono::seconds exceeded{0}; + if (!m_armed || !IsExpired(m_now(), exceeded)) + continue; + + m_armed = false; + const std::string stage = m_stage; + lock.unlock(); + m_onExpired(stage, exceeded); + lock.lock(); + } +} diff --git a/obs-studio-server/source/shutdown-watchdog.hpp b/obs-studio-server/source/shutdown-watchdog.hpp new file mode 100644 index 000000000..d06fc3da4 --- /dev/null +++ b/obs-studio-server/source/shutdown-watchdog.hpp @@ -0,0 +1,96 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace osn { + +namespace shutdown_budget { +constexpr std::chrono::seconds Prepare{15}; +constexpr std::chrono::seconds OutputStep{30}; +constexpr std::chrono::seconds OutputCap{180}; +constexpr std::chrono::seconds Teardown{30}; +} // namespace shutdown_budget + +// Terminates the process when a shutdown stage outlives its budget. While outputs are +// finalizing (see FinalizeTracker) the deadline is extended up to the cap set by SetCap(). +class ShutdownWatchdog { +public: + using Clock = std::chrono::steady_clock; + using NowFn = std::function; + using ExpiredFn = std::function; + + ShutdownWatchdog(NowFn now, ExpiredFn onExpired, std::chrono::milliseconds pollInterval = std::chrono::milliseconds(100)); + ~ShutdownWatchdog(); + + ShutdownWatchdog(const ShutdownWatchdog &) = delete; + ShutdownWatchdog &operator=(const ShutdownWatchdog &) = delete; + + // Process-wide instance that terminates the process on expiry (Windows only). Never destroyed. + static ShutdownWatchdog &Instance(); + + // Replaces the current stage and clears any cap. + void Arm(const std::string &stage, std::chrono::seconds budget); + void Kick(std::chrono::seconds budget); + void SetCap(std::chrono::seconds cap); + void Disarm(); + + void AddFinalizing(int delta); + +private: + void Run(); + bool IsExpired(Clock::time_point now, std::chrono::seconds &exceeded) const; + + const NowFn m_now; + const ExpiredFn m_onExpired; + const std::chrono::milliseconds m_pollInterval; + + std::mutex m_mtx; + std::condition_variable m_cv; + std::thread m_thread; + bool m_stop = false; + + bool m_armed = false; + std::string m_stage; + std::chrono::seconds m_budget{0}; + Clock::time_point m_deadline; + + struct Cap { + Clock::time_point at; + std::chrono::seconds limit; + }; + std::optional m_cap; + + int m_finalizing = 0; +}; + +// Counts one output as finalizing between Begin() and End(). End() without a Begin() is a no-op. +class FinalizeTracker { +public: + explicit FinalizeTracker(ShutdownWatchdog &watchdog) : m_watchdog(watchdog) {} + ~FinalizeTracker() { End(); } + + void Begin() + { + if (!m_active.exchange(true)) + m_watchdog.AddFinalizing(1); + } + + void End() + { + if (m_active.exchange(false)) + m_watchdog.AddFinalizing(-1); + } + +private: + ShutdownWatchdog &m_watchdog; + std::atomic m_active{false}; +}; + +} // namespace osn diff --git a/obs-studio-server/tests/test-shutdown-watchdog.cpp b/obs-studio-server/tests/test-shutdown-watchdog.cpp new file mode 100644 index 000000000..4e4f862b9 --- /dev/null +++ b/obs-studio-server/tests/test-shutdown-watchdog.cpp @@ -0,0 +1,192 @@ +#include "shutdown-watchdog.hpp" + +#include + +#include +#include +#include + +namespace { + +using namespace std::chrono_literals; + +struct FakeClock { + std::atomic seconds{0}; + + osn::ShutdownWatchdog::Clock::time_point Now() const { return osn::ShutdownWatchdog::Clock::time_point(std::chrono::seconds(seconds.load())); } +}; + +struct Fixture { + FakeClock clock; + std::atomic expiredCount{0}; + std::mutex mtx; + std::string expiredStage; + std::chrono::seconds expiredAfter{0}; + + osn::ShutdownWatchdog watchdog{[this] { return clock.Now(); }, + [this](const std::string &stage, std::chrono::seconds exceeded) { + std::lock_guard lock(mtx); + expiredStage = stage; + expiredAfter = exceeded; + expiredCount++; + }, + 1ms}; + + // Advances the fake clock and gives the polling thread time to observe it. + void Advance(long long secs) + { + clock.seconds += secs; + std::this_thread::sleep_for(50ms); + } +}; + +} // namespace + +TEST_CASE("Watchdog fires after the budget and names the stage", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Teardown", 30s); + + f.Advance(29); + REQUIRE(f.expiredCount == 0); + + f.Advance(2); + REQUIRE(f.expiredCount == 1); + REQUIRE(f.expiredStage == "Teardown"); + REQUIRE(f.expiredAfter == 30s); +} + +TEST_CASE("Watchdog fires once", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Prepare", 15s); + f.Advance(16); + f.Advance(100); + REQUIRE(f.expiredCount == 1); +} + +TEST_CASE("Kick re-arms the deadline", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Outputs", 30s); + + f.Advance(20); + f.watchdog.Kick(30s); + f.Advance(20); + REQUIRE(f.expiredCount == 0); + + f.Advance(11); + REQUIRE(f.expiredCount == 1); +} + +TEST_CASE("Disarm and Kick on a disarmed watchdog never fire", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Kick(1s); + f.Advance(10); + REQUIRE(f.expiredCount == 0); + + f.watchdog.Arm("Outputs", 30s); + f.watchdog.Disarm(); + f.Advance(100); + REQUIRE(f.expiredCount == 0); +} + +TEST_CASE("Finalizing outputs extend the deadline up to the cap and no further", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Outputs", 30s); + f.watchdog.SetCap(180s); + f.watchdog.AddFinalizing(1); + + f.Advance(100); + REQUIRE(f.expiredCount == 0); + f.Advance(79); + REQUIRE(f.expiredCount == 0); + + f.Advance(2); + REQUIRE(f.expiredCount == 1); + REQUIRE(f.expiredStage == "Outputs"); + REQUIRE(f.expiredAfter == 180s); +} + +TEST_CASE("Finishing a finalize starts a fresh step", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Outputs", 30s); + f.watchdog.SetCap(180s); + f.watchdog.AddFinalizing(1); + + f.Advance(100); + f.watchdog.AddFinalizing(-1); + f.Advance(29); + REQUIRE(f.expiredCount == 0); + + f.Advance(2); + REQUIRE(f.expiredCount == 1); + REQUIRE(f.expiredAfter == 30s); +} + +TEST_CASE("Finalizing does not extend a stage without a cap", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Teardown", 30s); + f.watchdog.AddFinalizing(1); + + f.Advance(31); + REQUIRE(f.expiredCount == 1); +} + +TEST_CASE("Arm clears the cap of the previous stage", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Outputs", 30s); + f.watchdog.SetCap(180s); + f.watchdog.Arm("Teardown", 30s); + f.watchdog.AddFinalizing(1); + + f.Advance(31); + REQUIRE(f.expiredCount == 1); + REQUIRE(f.expiredStage == "Teardown"); +} + +TEST_CASE("FinalizeTracker ignores End without Begin", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Outputs", 30s); + f.watchdog.SetCap(180s); + + osn::FinalizeTracker stopWithoutStopping(f.watchdog); + stopWithoutStopping.End(); + + // A negative count would wrongly keep this finalize from extending the deadline. + osn::FinalizeTracker tracker(f.watchdog); + tracker.Begin(); + f.Advance(100); + REQUIRE(f.expiredCount == 0); + + tracker.End(); + tracker.End(); + tracker.Begin(); + f.Advance(50); + REQUIRE(f.expiredCount == 0); +} + +TEST_CASE("FinalizeTracker counts Begin once and releases on destruction", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Outputs", 30s); + f.watchdog.SetCap(180s); + + { + osn::FinalizeTracker tracker(f.watchdog); + tracker.Begin(); + tracker.Begin(); + f.Advance(100); + REQUIRE(f.expiredCount == 0); + } + + f.Advance(31); + REQUIRE(f.expiredCount == 1); + REQUIRE(f.expiredAfter == 30s); +} From a254f84fc51b33a61ae8f1456628090517b1a4af Mon Sep 17 00:00:00 2001 From: Vladimir Sumarov Date: Tue, 3 Nov 2026 12:10:52 -0700 Subject: [PATCH 2/2] Keep finalize-end from extending uncapped watchdog stages Only the capped Outputs stage grants a fresh step per finished output; Prepare and Teardown must stay within their own budgets. Co-Authored-By: Claude Opus 5.5 --- obs-studio-server/source/shutdown-watchdog.cpp | 2 +- .../tests/test-shutdown-watchdog.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/obs-studio-server/source/shutdown-watchdog.cpp b/obs-studio-server/source/shutdown-watchdog.cpp index 5bcb80648..481d4eee2 100644 --- a/obs-studio-server/source/shutdown-watchdog.cpp +++ b/obs-studio-server/source/shutdown-watchdog.cpp @@ -98,7 +98,7 @@ void osn::ShutdownWatchdog::AddFinalizing(int delta) std::lock_guard lock(m_mtx); m_finalizing += delta; // Each output gets a fresh step once it finishes finalizing. - if (m_finalizing == 0 && delta < 0 && m_armed) + if (m_finalizing == 0 && delta < 0 && m_armed && m_cap) m_deadline = m_now() + m_budget; } diff --git a/obs-studio-server/tests/test-shutdown-watchdog.cpp b/obs-studio-server/tests/test-shutdown-watchdog.cpp index 4e4f862b9..6d186b3ed 100644 --- a/obs-studio-server/tests/test-shutdown-watchdog.cpp +++ b/obs-studio-server/tests/test-shutdown-watchdog.cpp @@ -137,6 +137,21 @@ TEST_CASE("Finalizing does not extend a stage without a cap", "[shutdown-watchdo REQUIRE(f.expiredCount == 1); } +TEST_CASE("Finishing a finalize does not move the deadline of a stage without a cap", "[shutdown-watchdog]") +{ + Fixture f; + f.watchdog.Arm("Prepare", 15s); + f.watchdog.AddFinalizing(1); + + f.Advance(14); + f.watchdog.AddFinalizing(-1); + f.Advance(2); + + REQUIRE(f.expiredCount == 1); + REQUIRE(f.expiredStage == "Prepare"); + REQUIRE(f.expiredAfter == 15s); +} + TEST_CASE("Arm clears the cap of the previous stage", "[shutdown-watchdog]") { Fixture f;