Skip to content

fix(ci): rustfmt test_support imports for PR #59#61

Merged
AlexanderWagnerDev merged 4 commits into
mainfrom
cursor/ci-autofix-automation-a056
Jul 8, 2026
Merged

fix(ci): rustfmt test_support imports for PR #59#61
AlexanderWagnerDev merged 4 commits into
mainfrom
cursor/ci-autofix-automation-a056

Conversation

@cursor

@cursor cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes failing cargo fmt --check on PR #59.

PR #59 added clear_rtmp_poll_server and set_rtmp_poll_server imports in src/test_support.rs with a layout that rustfmt rejects. This applies the expected two-line import grouping.

Failure: https://github.com/OpenRTMP/librtmp2-server/actions/runs/28912243143

Targets: cursor/application-security-review-bc92

Open in Web View Automation 

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Improved RTMP publish/play authentication reliability by ensuring the client connection is recognized before authorization checks execute.
    • Corrected IP-based RTMP publish rate-limiting so repeated failed attempts are counted only after the client connection is established.
    • Prevented failed publish attempts that occur before connection recognition from consuming the client’s IP-based auth budget.
  • Tests
    • Added coverage for RTMP publish auth throttling behavior for both pre- and post-connection scenarios, including transition from unregistered to registered state.

cursoragent and others added 3 commits July 8, 2026 02:05
Register client remote_addr inside publish/play callbacks during poll()
so per-IP auth failure tracking applies before the first publish/play
attempt. Adds regression tests for the pre-on_connect race.

Co-authored-by: Alexander Wagner <info@alexanderwagnerdev.com>
PR #59 added clear_rtmp_poll_server and set_rtmp_poll_server imports
that rustfmt wants on two lines instead of three.

Co-authored-by: Alexander Wagner <info@alexanderwagnerdev.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 90a0cb29-fb0f-4726-8de4-108727ddaf69

📥 Commits

Reviewing files that changed from the base of the PR and between 4e1c882 and 82f1e4f.

📒 Files selected for processing (2)
  • src/rtmp_bridge.rs
  • src/server.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/server.rs

📝 Walkthrough

Walkthrough

Adds thread-local pinning of the active RTMP server during polling so publish/play callbacks can register connections via on_connect before authorization checks run. Updates test support to use the new poll-server helpers and adds unit tests validating per-IP auth-rate limiting behavior.

Changes

RTMP auth registration fix

Layer / File(s) Summary
Thread-local poll server pointer and connection registration
src/server.rs
Adds std::cell::Cell-based thread-local RTMP_POLL_SERVER pointer with set_rtmp_poll_server/clear_rtmp_poll_server helpers, and ensure_conn_registered_for_auth which locates the connection and calls DbRtmpBridge::on_connect before auth checks.
Registration state and auth throttling tests
src/rtmp_bridge.rs
Adds DbRtmpBridge::is_registered(conn) and unit tests covering registration state transitions plus per-IP publish auth rate limiting before and after on_connect.
Test server polling hook
src/test_support.rs
Wraps RTMP test polling with the new set/clear poll-server helpers around server.poll(0).

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the stated goal of fixing rustfmt-related imports in test_support and is specific to the formatting issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/ci-autofix-automation-a056

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

@AlexanderWagnerDev AlexanderWagnerDev marked this pull request as ready for review July 8, 2026 08:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e1c882466

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server.rs
Comment on lines +98 to +102
let server = unsafe { &*server_ptr };
let Some(conn) = server
.connections
.iter()
.find(|c| c.conn_id == conn_id && c.client_fd >= 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid aliasing the RTMP server during callbacks

When a publish/play callback fires from server.poll(0), librtmp2::Server::poll(&mut self) is still inside its connection-processing loop, so self.connections is already mutably borrowed while a connection is being parsed. Dereferencing the thread-local raw pointer here creates a shared &Server and iterates the same connections vector reentrantly, which is undefined behavior in Rust even on the same thread; under live RTMP publish/play traffic this can miscompile or crash instead of just looking up the remote address. The callback path needs to avoid reading Server through a raw alias while poll owns &mut self (for example by having the library pass the remote address or by maintaining a separate pre-populated conn-id map).

Useful? React with 👍 / 👎.

Comment thread src/server.rs
else {
return;
};
with_rtmp_bridge(|bridge| bridge.on_connect(conn_id, &conn.remote_addr));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clean up pre-bookkeeping connection state

When a client sends an unauthorized publish/play and then disconnects before this poll() returns, this early on_connect creates a bridge ConnState but process_server_connections never sees the connection and therefore never adds it to tracked; the existing close-detection loop only calls on_close for tracked IDs, so these remote-IP-only entries remain in DbRtmpBridge::conns indefinitely. A burst of failed auth attempts that closes immediately after the command can grow that map without bound, bypassing the auth-failure bucket cap this change is trying to preserve.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/server.rs`:
- Around line 96-106: The `on_connect` callback in `src/server.rs` is creating a
shared `&Server` from `server_ptr` while `server.poll()` still holds a mutable
borrow, which violates Rust aliasing rules. Update this path to avoid forming
`&Server` from the raw pointer during polling; instead, read only the needed
`remote_addr` via raw pointer access or pass it through the callback from the
polling code, then call `with_rtmp_bridge(|bridge| bridge.on_connect(...))`
using that value.
🪄 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 Plus

Run ID: a58f6d6d-7b42-4594-9346-ab77058f3c64

📥 Commits

Reviewing files that changed from the base of the PR and between a46659e and 4e1c882.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • src/rtmp_bridge.rs
  • src/server.rs
  • src/test_support.rs

Comment thread src/server.rs
Comment on lines +96 to +106
// SAFETY: `RTMP_POLL_SERVER` is set only on the RTMP thread for the
// duration of `server.poll()`, which exclusively owns `server`.
let server = unsafe { &*server_ptr };
let Some(conn) = server
.connections
.iter()
.find(|c| c.conn_id == conn_id && c.client_fd >= 0)
else {
return;
};
with_rtmp_bridge(|bridge| bridge.on_connect(conn_id, &conn.remote_addr));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm poll takes &mut self and inspect the publish/play callback signatures
fd -t f 'server.rs' | rg -l 'fn poll' | xargs -r rg -nP -C2 'fn poll\s*\('
rg -nP -C3 'on_publish_cb|on_play_cb|type .*PublishCb|remote_addr' $(fd -t f '.rs' | rg -i 'librtmp2|server|types' | head -50) 2>/dev/null

Repository: OpenRTMP/librtmp2-server

Length of output: 2555


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- src/server.rs around the relevant code ---'
sed -n '1,140p' src/server.rs | cat -n

echo
echo '--- search for poll / thread-local server pointer usage ---'
rg -n -C 3 'set_rtmp_poll_server|RTMP_POLL_SERVER|poll\(0\)|server\.poll|on_publish_cb|on_play_cb|remote_addr' src/server.rs

echo
echo '--- all librtmp2 server method signatures available in repo ---'
rg -n -C 2 'pub fn poll|fn poll|on_publish_cb|on_play_cb|remote_addr' -g '*.rs' .

Repository: OpenRTMP/librtmp2-server

Length of output: 15077


Avoid creating &Server from server_ptr while poll() is active
server.poll(0) still holds &mut server when this callback runs, so let server = unsafe { &*server_ptr }; creates an aliased shared reference to the same object. That is UB under Rust’s aliasing rules; keep this path on raw pointers or pass remote_addr through the callback instead.

🤖 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/server.rs` around lines 96 - 106, The `on_connect` callback in
`src/server.rs` is creating a shared `&Server` from `server_ptr` while
`server.poll()` still holds a mutable borrow, which violates Rust aliasing
rules. Update this path to avoid forming `&Server` from the raw pointer during
polling; instead, read only the needed `remote_addr` via raw pointer access or
pass it through the callback from the polling code, then call
`with_rtmp_bridge(|bridge| bridge.on_connect(...))` using that value.

ensure_conn_registered_for_auth previously called bridge.on_connect
(and its "new connection" debug log line) on every single publish/play
callback for an already-registered connection, not just the first
time it needed to catch up before the poll-loop's normal on_connect
pass. Gate it behind DbRtmpBridge::is_registered so the reentrant
Server lookup and re-registration only happen once per connection.
@AlexanderWagnerDev AlexanderWagnerDev merged commit 56b030c into main Jul 8, 2026
11 checks passed
@AlexanderWagnerDev AlexanderWagnerDev deleted the cursor/ci-autofix-automation-a056 branch July 8, 2026 09:13
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.

3 participants