Skip to content

lib: warn once when process fd limit is very large - #22031

Merged
mjstapp merged 1 commit into
FRRouting:masterfrom
Jafaral:fd-limit-warn
May 21, 2026
Merged

lib: warn once when process fd limit is very large#22031
mjstapp merged 1 commit into
FRRouting:masterfrom
Jafaral:fd-limit-warn

Conversation

@Jafaral

@Jafaral Jafaral commented May 21, 2026

Copy link
Copy Markdown
Member

Each event_master_create() logged the same fd limit warning (e.g. zebra main plus dplane pthreads).

Each event_master_create() logged the same fd limit warning (e.g. zebra
main plus dplane pthreads).

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>

@mjstapp mjstapp 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.

sure - but is the new message too gentle?

@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR suppresses the repeated "FD Limit … is stupidly large" warning that fires once per event_master_create() call (main thread + dplane pthreads in zebra). It introduces a file-scoped static bool fd_limit_large_warned flag and gates zlog_warn() behind it, also lightly rewording the message.

  • The "warn once" gate is a plain non-atomic read-modify-write on a shared boolean with no mutex or memory ordering guarantee; two threads racing through event_master_create() at startup could both observe the flag as false and each emit the warning.
  • The message wording has been updated from "Is this what you intended?" to "Is this intentional?" for conciseness.

Confidence Score: 4/5

Safe to merge; worst case a duplicate warning is logged at startup when threads race.

The flag check-and-set is not protected by any synchronization primitive, so two threads racing through event_master_create() at daemon startup could both see the flag as unset and each emit the warning. This undermines the warn-once goal but has no functional impact beyond a duplicate log line.

lib/event.c β€” the fd_limit_large_warned flag and its unguarded check-then-set pattern.

Important Files Changed

Filename Overview
lib/event.c Introduces a static bool flag to suppress duplicate fd-limit warnings across multiple event_master_create() calls; flag is not protected against concurrent access, leaving a small window where the warning could fire more than once on parallel startup.

Sequence Diagram

sequenceDiagram
    participant Main as zebra main thread
    participant Dplane as dplane pthread
    participant EM as event_master_create()
    participant Flag as fd_limit_large_warned (static bool)

    Main->>EM: event_master_create("main")
    EM->>Flag: read false
    EM->>Flag: write true
    EM->>EM: zlog_warn emitted once

    Dplane->>EM: event_master_create("dplane")
    EM->>Flag: read true
    EM->>EM: warning suppressed

    Note over Main,Dplane: Race window concurrent startup
    Main-->>EM: event_master_create()
    Dplane-->>EM: event_master_create()
    EM-->>Flag: both read false simultaneously
    EM-->>Flag: both write true
    EM-->>EM: warning emitted TWICE
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
lib/event.c:771-775
**Non-atomic check-then-set on shared flag**

`fd_limit_large_warned` is a plain `static bool` with no synchronization. If two threads call `event_master_create()` concurrently (e.g., the zebra main thread and a dplane pthread racing at startup), both can observe `fd_limit_large_warned == false` before either writes `true`, causing the warning to fire twice β€” the exact scenario this PR aims to prevent. A `pthread_once` guard (reusing the existing `init_once` pattern already present in this file) or a C11 `_Atomic bool` would close the window.

Reviews (1): Last reviewed commit: "lib: warn once when process fd limit is ..." | Re-trigger Greptile

Comment thread lib/event.c
Comment on lines +771 to +775
if (frr_is_daemon() && !fd_limit_large_warned) {
fd_limit_large_warned = true;
zlog_warn("FD Limit set: %u is too large. Is this intentional? Consider using --limit-fds. Limiting size to %u",
rv->fd_limit, STUPIDLY_LARGE_FD_SIZE);
}

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 Non-atomic check-then-set on shared flag

fd_limit_large_warned is a plain static bool with no synchronization. If two threads call event_master_create() concurrently (e.g., the zebra main thread and a dplane pthread racing at startup), both can observe fd_limit_large_warned == false before either writes true, causing the warning to fire twice β€” the exact scenario this PR aims to prevent. A pthread_once guard (reusing the existing init_once pattern already present in this file) or a C11 _Atomic bool would close the window.

Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/event.c
Line: 771-775

Comment:
**Non-atomic check-then-set on shared flag**

`fd_limit_large_warned` is a plain `static bool` with no synchronization. If two threads call `event_master_create()` concurrently (e.g., the zebra main thread and a dplane pthread racing at startup), both can observe `fd_limit_large_warned == false` before either writes `true`, causing the warning to fire twice β€” the exact scenario this PR aims to prevent. A `pthread_once` guard (reusing the existing `init_once` pattern already present in this file) or a C11 `_Atomic bool` would close the window.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@greptile, that was intentional, i.e, no need for added complexity. worst case we get the log msg more than once as before.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fair enough β€” the race window is tiny and the worst case is harmless (an extra log line), so the added complexity isn't worth it. Thanks for the clarification!

Tip: You can give me more context with .greptile/rules.md so I get this right next time.

@Jafaral

Jafaral commented May 21, 2026

Copy link
Copy Markdown
Member Author

sure - but is the new message too gentle?

I figured we had that long enough! we can be gentle moving forward πŸ˜‚

@choppsv1

Copy link
Copy Markdown
Contributor

I get this warning when I run in some container environments, I have no idea what it means and it annoys me. Does this limit somehow adversely affect the operation of FRR? If it doesn't then we should just get rid of it IMO.

@choppsv1

Copy link
Copy Markdown
Contributor

I get this warning when I run in some container environments, I have no idea what it means and it annoys me. Does this limit somehow adversely affect the operation of FRR? If it doesn't then we should just get rid of it IMO.

Apparently it does, as we need to allocate arrays based on it.

@mjstapp

mjstapp commented May 21, 2026

Copy link
Copy Markdown
Contributor

yes, it was used more before we did the epoll() conversion in the event/scheduling component; I think it's not used much otherwise.

I get this warning when I run in some container environments, I have no idea what it means and it annoys me. Does this limit somehow adversely affect the operation of FRR? If it doesn't then we should just get rid of it IMO.

Apparently it does, as we need to allocate arrays based on it.

@mjstapp
mjstapp merged commit 917c83e into FRRouting:master May 21, 2026
36 of 37 checks passed
@Jafaral

Jafaral commented May 21, 2026

Copy link
Copy Markdown
Member Author

I get this warning when I run in some container environments, I have no idea what it means and it annoys me. Does this limit somehow adversely affect the operation of FRR? If it doesn't then we should just get rid of it IMO.

It is annoying. One way to make it go away is to ulimit -n 100000

@Jafaral
Jafaral deleted the fd-limit-warn branch May 21, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants