Skip to content

rtmp-services: Ingest refresh waits on an event instead of polling (#1284) - #1326

Merged
zackees merged 2 commits into
masterfrom
fix/1284-ingest-refresh-wait
Oct 17, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/1284-ingest-refresh-wait

Conversation

@zackees

@zackees zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Fixes #1284 (parent #1273).

Callers and threads

  • service_ingests_refresh (Twitch / Amazon IVS) is reached from:
    • rtmp_common_url ("auto" server), called through obs_service_get_url / connect info, mainly on the output's start/connect thread (rtmp-stream), and from frontend code that reads the service URL.
    • The twitch_ingests_refresh / amazon_ivs_ingests_refresh proc handlers, called by AutoConfig::AutoConfig (frontend/wizards/AutoConfig.cpp.hpp) on the UI thread with seconds = 5.
  • dacast_ingests_load_data is called from rtmp_common_url for Dacast (output connect thread, or any caller reading the URL), with a 3 s timeout.
  • The refresh itself runs on the file-updater single_file_thread, which calls ingest_update / dacast_ingest_update when a download arrives.

Cause

Both waits polled a flag every 10 ms until a timeout. service-ingest waits only while ingests_loaded is false (no cached or downloaded list), then polls ingests_refreshed. That flag is set only when the download parsed, so a download that arrived but failed to parse kept the caller waiting the full timeout, even though the refresh had already ended. Dacast had the same problem with ingests_loaded.

What the flags mean: ingests_loaded means a usable list exists (from the cache or a download). ingests_refreshed means this session's download succeeded, and it sets loaded as well. The intended rule is "wait only when there is no list at all, until the refresh attempt ends". It is now written out as ingest_refresh_needs_wait(refreshed, loaded) = !refreshed && !loaded.

Fix

  • New header-only helper plugins/rtmp-services/service-specific/ingest-refresh-wait.h wraps a manual-reset os_event_t:
    • reset runs when a refresh starts.
    • complete runs from the update callback whatever the outcome.
    • wait_for is os_event_timedwait(timeout).
  • service-ingest and dacast both use the helper. It is included through service-ingest.h, which is already in the rtmp-services PCH.
  • Otherwise behaviour is unchanged: same timeouts, same flags, same early return once a refresh has succeeded.
  • Unchanged: if the HTTP request itself fails, file-updater never calls the callback, so the wait still ends at the timeout, as before. Fixing that needs a change to file-updater and is out of scope here.

Tests

New test/cmocka/test_ingest_refresh_wait.c (+ tests.d/test_ingest_refresh_wait.cmake, links only libobs + cmocka). It uses the same helper as the plugin:

  • A successful fake refresh completes after 50 ms, and the wait returns in [40, 150) ms.
  • A failed (unparsed) refresh completes after 50 ms, and the wait still returns in < 150 ms.
  • A refresh that never completes: the 300 ms timeout holds (returns false, elapsed >= 290 ms).
  • A completed wait returns at once until it is reset.
  • The needs_wait truth table over (refreshed, loaded).

RED (c602060c9, the stub keeps the old polling and flag semantics): rust/tools/linux-validate/run.sh gave 99% tests passed, 1 tests failed out of 284, and the only failure was test_ingest_refresh_wait. It failed failed_refresh_ends_wait (waited the full timeout), completed_wait_returns_at_once_until_reset and needs_wait_only_without_any_list.

GREEN: 100% tests passed, 0 tests failed out of 284, and test_ingest_refresh_wait passed in 0.48 s, including the repeat run. ./lint passes.

There were no existing rtmp-services tests. The validator does not build the plugin itself, and this host has no jansson for a local compile, so PR CI's plugins/rtmp-services Linux build lane is the compile check for the plugin changes.

Tiers: this is a C plugin bug fix with no Rust port involved, so Tiers 1, 3 and 4 do not apply. Tier 2 is the new cmocka test.

@zackees
zackees enabled auto-merge October 17, 2026 19:19
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 17, 2026
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into master with commit eeb9ef1 Oct 17, 2026
30 checks passed
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 17, 2026
… ms (obs-rust#1338)

test_ingest_refresh_wait (obs-rust#1326) required a 50 ms refresh to end the wait
within 150 ms; a loaded macOS runner overslept it (failed_refresh_ends_wait,
line 66, Tier 2 macos-26 on obs-rust#1336). What the test proves is that the wait
ends at the refresh and not at the 5000 ms timeout, so bound it at 1000 ms.

Refs obs-rust#1284, obs-rust#838
@zackees
zackees deleted the fix/1284-ingest-refresh-wait branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rtmp-services: ingest refresh waits poll every 10 ms for up to 5 s (flag mismatch; possibly on the UI thread)

1 participant