Skip to content

Connection: Add stop signals for connection failures and reconnections#36

Open
danrossi wants to merge 3 commits into
moq-dev:mainfrom
danrossi:connection-stop-signals
Open

Connection: Add stop signals for connection failures and reconnections#36
danrossi wants to merge 3 commits into
moq-dev:mainfrom
danrossi:connection-stop-signals

Conversation

@danrossi
Copy link
Copy Markdown

The OBS plugin was missing stop signals on connection failures to stop the broadcast and produce a dialog. This has been added including signalling for reconnection. It retries the connection once but another signal is required to continue reattempts. The flags is setup for that. I am not sure of the right signal to tell OBS to keep reconnecting on a server cut.

danrossi added 3 commits May 14, 2026 19:16
- add initial reconnection attempt feature. Needs to signal to keep trying to reconnect
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

Walkthrough

This PR introduces reconnection state tracking to the MoQOutput class. A new volatile bool reconnecting member is declared and initialized to false in the constructor. The include of util/threading.h enables atomic operations. The MoQ session connection callback is enhanced with three distinct branches: successful connection clears the reconnecting flag, error code -2 (a specific disconnection case) signals OBS_OUTPUT_DISCONNECTED and sets reconnecting to true, while other errors signal connection failure and clear the flag. The Stop method atomically resets reconnecting to false.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding stop signals for connection failures and reconnections, which matches the core functionality implemented in the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale for adding stop signals on connection failures and the reconnection feature with the reconnecting flag.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/moq-output.cpp`:
- Line 90: Update the inline comment that currently reads "on swrver
disconnection. Signal to attempt to reconnect" to correct the typo so it reads
"on server disconnection. Signal to attempt to reconnect"; locate the comment
string (e.g., within the moq-output component where that disconnection/reconnect
logic is implemented) and replace "swrver" with "server" so the comment is clear
and accurate.
- Around line 86-88: The access to the boolean flag reconnecting is
inconsistent: replace the non-atomic read self->reconnecting with an atomic load
using os_atomic_load_bool(&self->reconnecting) so both read and write use the
same atomic API; update the check that currently reads self->reconnecting and
keep the atomic write via os_atomic_set_bool(&self->reconnecting, false)
unchanged to ensure thread-safe access to reconnecting.
- Line 149: In Stop() there’s an undefined identifier `self`; replace
`os_atomic_set_bool(&self->reconnecting, false);` with a proper member reference
such as `os_atomic_set_bool(&this->reconnecting, false);` (or `&reconnecting`)
so the class member `reconnecting` is accessed from Stop(); locate the Stop()
method and update that call (the lambda earlier that used `self` can remain
unchanged).

In `@src/moq-output.h`:
- Line 50: Remove the volatile qualifier from the member declaration
"reconnecting" so it is a plain bool; the code uses OBS atomic helpers like
os_atomic_set_bool/os_atomic_get_bool which expect a regular bool (or the type
they manage) and provide the necessary synchronization, so update the
declaration of reconnecting accordingly and ensure any other uses rely on
os_atomic_* functions rather than volatile semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 969ad5c6-15da-43d2-b2a3-fa3ebd8c37ae

📥 Commits

Reviewing files that changed from the base of the PR and between ae7df7a and 580a319.

📒 Files selected for processing (2)
  • src/moq-output.cpp
  • src/moq-output.h

Comment thread src/moq-output.cpp
Comment on lines +86 to +88

if (self->reconnecting)
os_atomic_set_bool(&self->reconnecting, false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Inconsistent atomic access to reconnecting.

Line 87 reads self->reconnecting non-atomically (direct access), but line 88 writes it atomically using os_atomic_set_bool. For proper thread safety, both read and write operations should use atomic functions. Use os_atomic_load_bool(&self->reconnecting) for the read.

🔒 Proposed fix for consistent atomic access
-			if (self->reconnecting)
-				os_atomic_set_bool(&self->reconnecting, false);
+			if (os_atomic_load_bool(&self->reconnecting))
+				os_atomic_set_bool(&self->reconnecting, false);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.cpp` around lines 86 - 88, The access to the boolean flag
reconnecting is inconsistent: replace the non-atomic read self->reconnecting
with an atomic load using os_atomic_load_bool(&self->reconnecting) so both read
and write use the same atomic API; update the check that currently reads
self->reconnecting and keep the atomic write via
os_atomic_set_bool(&self->reconnecting, false) unchanged to ensure thread-safe
access to reconnecting.

Comment thread src/moq-output.cpp
if (self->reconnecting)
os_atomic_set_bool(&self->reconnecting, false);
} else if (error_code == -2) {
//on swrver disconnection. Signal to attempt to reconnect
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix typo in comment.

"swrver" should be "server".

📝 Proposed fix
-			//on swrver disconnection. Signal to attempt to reconnect
+			//on server disconnection. Signal to attempt to reconnect
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
//on swrver disconnection. Signal to attempt to reconnect
//on server disconnection. Signal to attempt to reconnect
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.cpp` at line 90, Update the inline comment that currently
reads "on swrver disconnection. Signal to attempt to reconnect" to correct the
typo so it reads "on server disconnection. Signal to attempt to reconnect";
locate the comment string (e.g., within the moq-output component where that
disconnection/reconnect logic is implemented) and replace "swrver" with "server"
so the comment is clear and accurate.

Comment thread src/moq-output.cpp
obs_output_signal_stop(output, OBS_OUTPUT_SUCCESS);
}

os_atomic_set_bool(&self->reconnecting, false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if the code compiles and look for build errors

# Search for any similar patterns where self might be misused
rg -n '\bself->' src/moq-output.cpp

Repository: moq-dev/obs

Length of output: 925


🏁 Script executed:

# Read the code around the lambda callback (lines 78-100)
sed -n '75,105p' src/moq-output.cpp | cat -n

# Read the code around line 149
sed -n '140,160p' src/moq-output.cpp | cat -n

Repository: moq-dev/obs

Length of output: 2299


Critical: Undefined variable self in Stop() method.

Line 149 uses &self->reconnecting, but self is not defined in this scope. The variable self only exists within the lambda callback (lines 78-103). In the Stop() method, use &this->reconnecting or &reconnecting instead.

This is a compilation error that will prevent the build from succeeding.

Proposed fix
-	os_atomic_set_bool(&self->reconnecting, false);
+	os_atomic_set_bool(&reconnecting, false);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
os_atomic_set_bool(&self->reconnecting, false);
os_atomic_set_bool(&reconnecting, false);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.cpp` at line 149, In Stop() there’s an undefined identifier
`self`; replace `os_atomic_set_bool(&self->reconnecting, false);` with a proper
member reference such as `os_atomic_set_bool(&this->reconnecting, false);` (or
`&reconnecting`) so the class member `reconnecting` is accessed from Stop();
locate the Stop() method and update that call (the lambda earlier that used
`self` can remain unchanged).

Comment thread src/moq-output.h
std::map<obs_encoder_t *, int> video_tracks;
std::map<obs_encoder_t *, int> audio_tracks;

volatile bool reconnecting;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check OBS threading utility signatures for atomic bool operations

# Search for os_atomic_set_bool and os_atomic_load_bool declarations
rg -n -A2 -B2 'os_atomic_(set|load)_bool' --type=c --type=cpp

Repository: moq-dev/obs

Length of output: 1220


🏁 Script executed:

# Find where os_atomic_set_bool is declared/defined
rg -n 'os_atomic_set_bool|define.*os_atomic_set_bool' --type=c --type=h --type=hpp

Repository: moq-dev/obs

Length of output: 83


🏁 Script executed:

# Also search in common OBS headers or utility files for atomic macros/functions
fd -e h -e hpp | xargs rg -l 'atomic' | head -20

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Check the actual declaration in moq-output.h around line 50
cat -n src/moq-output.h | sed -n '45,55p'

Repository: moq-dev/obs

Length of output: 317


🏁 Script executed:

# Search for os_atomic_set_bool definition across header and source files (.h, .c)
rg -n 'os_atomic_set_bool' --type=c --type=h -B3 -A3

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Look for the definition in typical OBS locations or macros
rg -n 'define.*atomic|#define.*set_bool' --type=c --type=h

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Check what headers are included in moq-output.h to understand where os_atomic comes from
head -30 src/moq-output.h

Repository: moq-dev/obs

Length of output: 591


🏁 Script executed:

# Search for all os_atomic usages in the codebase to see the pattern
rg -n 'os_atomic' --type=c --type=h

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Look for other volatile declarations in the codebase
rg -n 'volatile' --type=c --type=h

Repository: moq-dev/obs

Length of output: 107


🏁 Script executed:

# Check for any compilation or type-related issues - look at build configuration
find . -name "CMakeLists.txt" -o -name "Makefile" -o -name "build.sh" | head -5

Repository: moq-dev/obs

Length of output: 72


🏁 Script executed:

# Check CMakeLists.txt to understand build configuration and dependencies
head -50 ./CMakeLists.txt

Repository: moq-dev/obs

Length of output: 1646


🏁 Script executed:

# Look at actual usage context in moq-output.cpp around the os_atomic_set_bool calls
sed -n '85,100p' src/moq-output.cpp

Repository: moq-dev/obs

Length of output: 740


🏁 Script executed:

# Check if there are any warnings or issues related to type mismatches
# Look for any casting or type conversions around reconnecting variable
rg -n 'reconnecting' --type=c --type=h -B1 -A1

Repository: moq-dev/obs

Length of output: 151


Remove volatile qualifier from reconnecting member—it conflicts with atomic operation semantics.

The reconnecting member is declared as volatile bool but accessed using os_atomic_set_bool in the implementation. In C++, volatile does not provide atomicity or memory ordering guarantees—it only prevents compiler optimizations. When using atomic operations, the variable should be declared as a plain bool, allowing the OBS atomic functions to handle all necessary synchronization.

Proposed fix
-    volatile bool reconnecting;
+    bool reconnecting;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
volatile bool reconnecting;
bool reconnecting;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.h` at line 50, Remove the volatile qualifier from the member
declaration "reconnecting" so it is a plain bool; the code uses OBS atomic
helpers like os_atomic_set_bool/os_atomic_get_bool which expect a regular bool
(or the type they manage) and provide the necessary synchronization, so update
the declaration of reconnecting accordingly and ensure any other uses rely on
os_atomic_* functions rather than volatile semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant