lib: warn once when process fd limit is very large - #22031
Conversation
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
left a comment
There was a problem hiding this comment.
sure - but is the new message too gentle?
Greptile SummaryThis PR suppresses the repeated "FD Limit β¦ is stupidly large" warning that fires once per
Confidence Score: 4/5Safe 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
Sequence DiagramsequenceDiagram
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
Prompt To Fix All With AIFix 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 |
| 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); | ||
| } |
There was a problem hiding this 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.
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.There was a problem hiding this comment.
@greptile, that was intentional, i.e, no need for added complexity. worst case we get the log msg more than once as before.
There was a problem hiding this comment.
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.
I figured we had that long enough! we can be gentle moving forward π |
|
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. |
|
yes, it was used more before we did the epoll() conversion in the event/scheduling component; I think it's not used much otherwise.
|
It is annoying. One way to make it go away is to |
Each event_master_create() logged the same fd limit warning (e.g. zebra main plus dplane pthreads).