From ca8abb5f33df51c4f578adb7477210afc54f5e7b Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Tue, 27 Oct 2026 19:17:39 -0700 Subject: [PATCH 1/3] test(obs-websocket): Pin the bounded, mutex-guarded session drain (RED) Stop() polled `_sessions.size()` with no lock while onClose() erased from the same std::map under `sessionMutex`, and the poll had no bound, so a client that never answered the close frame kept obs_module_unload from returning: uv run --no-project -m unittest ci/test_websocket_submodule.py FAILED (failures=3, errors=1) - `test_pointer_keeps_the_bounded_session_drain`: the pointer is 30d6f511, which predates obs-rust/obs-websocket#22. - `SessionDrainShapeTest`: no `_sessionsDrained.wait_for(`, no `kSessionDrainTimeout`, and the unlocked `while (_sessions.size() > 0)` poll is still there. Green is the submodule bump to 3253206. Refs #2713 --- ci/test_websocket_submodule.py | 57 +++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/ci/test_websocket_submodule.py b/ci/test_websocket_submodule.py index 5180d4082b..30f1866afc 100644 --- a/ci/test_websocket_submodule.py +++ b/ci/test_websocket_submodule.py @@ -18,6 +18,9 @@ ROOT = Path(__file__).resolve().parent.parent SUBMODULE = "plugins/obs-websocket" BOUNDED_PARSER = "7d89109c90a60ed119cf38fa4e35eae774959d7f" +# obs-rust/obs-websocket#22: Stop() reads the drain predicate under the session +# mutex and bounds the wait (obs-studio#2713). +BOUNDED_SESSION_DRAIN = "3253206ff1ba62213936f4e9458e0ebf5eb421ea" # Upstream commits without the fix that stale checkouts have committed (#492, #496). KNOWN_BAD = {"073a294cd0646fa1744b0ebf3293bfa63a869b50"} @@ -27,26 +30,64 @@ def git(*args: str, cwd: Path = ROOT) -> subprocess.CompletedProcess: class WebsocketSubmoduleTest(unittest.TestCase): - def test_pointer_keeps_the_bounded_parser(self): + def _assert_pointer_at_least(self, commit: str, what: str) -> None: tree = git("ls-tree", "HEAD", SUBMODULE).stdout.split() self.assertEqual(tree[:2], ["160000", "commit"], f"{SUBMODULE} is not a submodule") pointer = tree[2] - self.assertNotIn(pointer, KNOWN_BAD, f"{SUBMODULE} points at upstream {pointer[:9]}, without the bounded parser (#99)") - if pointer == BOUNDED_PARSER: + self.assertNotIn(pointer, KNOWN_BAD, f"{SUBMODULE} points at upstream {pointer[:9]}, without {what}") + if pointer == commit: return sub = ROOT / SUBMODULE if not (sub / ".git").exists(): self.skipTest(f"{SUBMODULE} is not checked out; cannot check ancestry of {pointer}") - has = git("merge-base", "--is-ancestor", BOUNDED_PARSER, pointer, cwd=sub) - if has.returncode != 0 and git("rev-parse", "--is-shallow-repository", cwd=sub).stdout.strip() == "true": - # A shallow checkout may stop above BOUNDED_PARSER, so a miss here proves nothing. - self.skipTest(f"{SUBMODULE} history is shallow; cannot check ancestry of {pointer[:9]}") + has = git("merge-base", "--is-ancestor", commit, pointer, cwd=sub) + if has.returncode != 0: + known = git("cat-file", "-e", f"{commit}^{{commit}}", cwd=sub).returncode == 0 + shallow = git("rev-parse", "--is-shallow-repository", cwd=sub).stdout.strip() == "true" + if not known and shallow: + # A shallow checkout may stop above the fix, so a miss here proves nothing. + self.skipTest(f"{SUBMODULE} history is shallow; cannot check ancestry of {pointer[:9]}") self.assertEqual( has.returncode, 0, - f"{SUBMODULE} points at {pointer[:9]}, which lacks the bounded parser {BOUNDED_PARSER[:9]} (#99)", + f"{SUBMODULE} points at {pointer[:9]}, which lacks {what} {commit[:9]}", ) + def test_pointer_keeps_the_bounded_parser(self): + self._assert_pointer_at_least(BOUNDED_PARSER, "the bounded parser (#99)") + + def test_pointer_keeps_the_bounded_session_drain(self): + self._assert_pointer_at_least(BOUNDED_SESSION_DRAIN, "the bounded session drain (#2713)") + + +class SessionDrainShapeTest(unittest.TestCase): + """Stop() must read the drain predicate under the session mutex and bound the wait.""" + + def setUp(self) -> None: + self.source = ROOT / SUBMODULE / "src/websocketserver/WebSocketServer.cpp" + if not self.source.is_file(): + self.skipTest(f"{self.source} is not checked out") + self.text = self.source.read_text(encoding="utf-8") + + def test_stop_waits_on_the_predicate_under_the_mutex(self) -> None: + stop = self.text[self.text.index("void WebSocketServer::Stop()") :] + stop = stop[: stop.index("_serverThread.join()")] + self.assertIn("_sessionsDrained.wait_for(", stop) + self.assertIn("_sessions.empty()", stop) + self.assertIn("lock.lock()", stop) + self.assertIn("_sessionMutex", self.text, "Stop() must wait on the same mutex onClose() erases under") + self.assertNotIn("while (_sessions.size() > 0)", self.text, "the unbounded unlocked poll must be gone; it races onClose()'s erase") + + def test_the_wait_is_bounded_and_reports_what_did_not_close(self) -> None: + self.assertRegex(self.text, r"kSessionDrainTimeout = std::chrono::seconds\(\d+\)") + self.assertIn("still open after", self.text, "an abandoned drain must name the sessions it gave up on") + self.assertIn("DescribeSessions(_sessions)", self.text) + + def test_onclose_wakes_the_drain_after_erasing(self) -> None: + close = self.text[self.text.index("void WebSocketServer::onClose(") :] + close = close[: close.index("\n}", close.index("_sessionsDrained"))] + self.assertLess(close.index("_sessions.erase(hdl)"), close.index("_sessionsDrained.notify_all()")) + if __name__ == "__main__": unittest.main() From 819d3f5cd814fd5b0f83d4457feb875cfa3e1e75 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Tue, 27 Oct 2026 19:17:44 -0700 Subject: [PATCH 2/3] fix(obs-websocket): Bump the submodule to the bounded session drain (#22) obs-rust/obs-websocket#22 made WebSocketServer::Stop() wait on a condition variable whose predicate is read under `sessionMutex`, bounded it at 5 s, and logs the sessions that did not close instead of spinning forever, so obs_module_unload can always return. plugins/obs-websocket: 30d6f511 -> 3253206 (merge of #22). GREEN of the RED in the previous commit: uv run --no-project -m unittest ci/test_websocket_submodule.py Ran 5 tests ... OK (skipped=1: bounded-parser ancestry is unknowable in a shallow checkout) Refs #2713 --- plugins/obs-websocket | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/obs-websocket b/plugins/obs-websocket index 30d6f51155..3253206ff1 160000 --- a/plugins/obs-websocket +++ b/plugins/obs-websocket @@ -1 +1 @@ -Subproject commit 30d6f511551813f2c3b612df8a7d89afc464090a +Subproject commit 3253206ff1ba62213936f4e9458e0ebf5eb421ea From 7911c183087b23316623a64dd44d76f388cb0b26 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Tue, 27 Oct 2026 19:17:53 -0700 Subject: [PATCH 3/3] docs(features): Record the obs-websocket shutdown drain fix (#2713) --- docs/features.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/features.md b/docs/features.md index 027c230e16..f2a45d90e0 100644 --- a/docs/features.md +++ b/docs/features.md @@ -2324,6 +2324,15 @@ area. [#2672](https://github.com/obs-rust/obs-studio/issues/2672), PR [#2673](https://github.com/obs-rust/obs-studio/pull/2673); obsproject/obs-studio `shared/file-updater`. +- A WebSocket client that never answers the close frame no longer keeps OBS + from quitting. The obs-websocket server waits for its sessions to close on a + condition variable read under the session mutex, bounded at 5 s, and logs + which clients did not close, instead of polling the session list with no lock + (a data race with the IO thread's erase) and spinning forever. *All*, pending + merge. Issue + [#2713](https://github.com/obs-rust/obs-studio/issues/2713); + obs-rust/obs-websocket + [#22](https://github.com/obs-rust/obs-websocket/pull/22). ### Security hardening