Skip to content

More network fixes and improvements#2194

Merged
limetech merged 8 commits into
unraid:masterfrom
bergware:master
May 10, 2025
Merged

More network fixes and improvements#2194
limetech merged 8 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented May 10, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Simplified and streamlined the handling of network interface monitoring and static IP address storage.
    • Improved logic for detecting stable state changes in network interfaces and managing IP addresses.
    • Enhanced idle detection for nchan subscribers with more robust multi-step checks.
  • Style
    • Minor adjustments to background process handling for improved script behavior.

@coderabbitai

coderabbitai Bot commented May 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The updates modify four scripts related to network and process management. They adjust how background jobs are handled, refactor static IP address recording, simplify and change the logic for interface state monitoring, and introduce improved idle detection for nchan subscribers. No public APIs or exported declarations are added or removed.

Changes

Files/Paths Change Summary
etc/rc.d/rc.docker Removed the disown command from background job handling in the 'start' and 'restart' cases, leaving background jobs attached to the shell.
sbin/create_network_ini Changed static IP assignment recording: now directly appends filtered output from ip commands to the $STA file, removing the previous variable construction and conditional echo logic.
sbin/monitor_interface Refactored the switch and init functions, simplified interface config parsing, adjusted state change detection logic, and changed how IP addresses are applied on state changes. Introduced a new variable for tracking the last processed interface.
sbin/monitor_nchan Refactored idle subscriber detection: added nchan_subs and nchan_idle functions for multi-step idle checks, replacing previous simpler logic. Now logs and stops nchan processes if idle is detected after three checks.

Sequence Diagram(s)

sequenceDiagram
    participant MonitorInterface
    participant NetworkInterface
    participant System

    loop Every 3 seconds
        MonitorInterface->>NetworkInterface: Check interface state
        alt State changed to "up"
            MonitorInterface->>System: ip addr add dev <line>
        else State changed to "down" and new interface
            MonitorInterface->>System: ip addr flush dev <interface> scope global
        end
    end
Loading
sequenceDiagram
    participant MonitorNchan
    participant Nginx
    participant System

    loop Every 30 seconds
        MonitorNchan->>Nginx: Get subscriber count (curl to socket)
        loop 3 times, 3s apart
            MonitorNchan->>Nginx: Check subscriber count
        end
        alt Idle detected (all 3 checks zero)
            MonitorNchan->>System: Log idle, stop nchan, cleanup
        end
    end
Loading

Suggested labels

7.2

Poem

Oh, what a hop through code today,
Where scripts now check, then swiftly play—
No more disown, the jobs still bound,
Interfaces up and down are found.
Nchan listens, counts with care,
While static IPs are written fair.
🐇✨ Another patch—beyond compare!


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
sbin/create_network_ini (2)

185-186: Minor nit: unnecessary subshell

All four echo "$(ip … | awk …)" statements spawn an extra subshell for echo.
printf (or plain command substitution without echo) is marginally faster and avoids an extra fork:

-echo "$(ip -6 -br addr show … | awk …)" >>$STA
+ip -6 -br addr show … | awk '{$2="";print;exit}' >>$STA

214-215: Duplicate code – could be extracted to a helper

The IPv4 and IPv6 static-address blocks for both parent and VLAN interfaces are identical except for the ip -4/-6 switch. A small function would remove four nearly-identical code chunks and cut maintenance cost.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e0895b and 0a5e4b5.

📒 Files selected for processing (4)
  • etc/rc.d/rc.docker (0 hunks)
  • sbin/create_network_ini (4 hunks)
  • sbin/monitor_interface (2 hunks)
  • sbin/monitor_nchan (2 hunks)
💤 Files with no reviewable changes (1)
  • etc/rc.d/rc.docker
🔇 Additional comments (2)
sbin/create_network_ini (1)

164-166: Static-IP line now contains interface + address – confirm downstream parsing

The new format (eth0 192.0.2.10/24) is simpler, but any tool that used to rely on the previous IPADDR=<addr> METRIC=<n> layout must be adjusted.
monitor_interface was updated in this PR, so the change looks intentional. Just make sure no other scripts (e.g. plugin hooks) still expect the old layout.

sbin/monitor_interface (1)

52-66: LAST deduplication logic may miss multi-address interfaces

ip addr flush scope global dev $INT is skipped when the same interface appears twice in a row (common on multinet setups).
Consider tracking interface-state transitions instead of using a single LAST variable, or always flushing when the state actually changed to down.

Comment thread sbin/monitor_nchan
Comment thread sbin/monitor_interface
@limetech limetech merged commit 233a2d0 into unraid:master May 10, 2025
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.

2 participants