fix: Caching flows with no template #2843
No reviewers
Labels
No labels
1week
2weeks
Failed compliance check
IP cameras
NATS
Possible security concern
Review effort 1/5
Review effort 2/5
Review effort 3/5
Review effort 4/5
Review effort 5/5
UI
aardvark
accessibility
amd64
api
arm64
auth
back-end
bgp
blog
bug
build
checkers
ci-cd
cleanup
cnpg
codex
core
dependencies
device-management
documentation
duplicate
dusk
ebpf
enhancement
eta 1d
eta 1hr
eta 3d
eta 3hr
feature
fieldsurvey
github_actions
go
good first issue
help wanted
invalid
javascript
k8s
log-collector
mapper
mtr
needs-triage
netflow
network-sweep
observability
oracle
otel
plug-in
proton
python
question
reddit
redhat
research
rperf
rperf-checker
rust
sdk
security
serviceradar-agent
serviceradar-agent-gateway
serviceradar-web
serviceradar-web-ng
siem
snmp
sysmon
topology
ubiquiti
wasm
wontfix
zen-engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
carverauto/serviceradar!2843
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2843/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from GitHub pull request.
Original GitHub pull request: #2689
Original author: @mikemiles-dev
Original URL: https://github.com/carverauto/serviceradar/pull/2689
Original created: 2026-02-03T22:32:44Z
Original updated: 2026-02-05T06:54:50Z
Original head: mikemiles-dev/serviceradar:fix/ISSUE_2678
Original base: staging
User description
IMPORTANT: Please sign the Developer Certificate of Origin
Thank you for your contribution to ServiceRadar. Please note, when contributing, the developer must include
a DCO sign-off statement indicating the DCO acceptance in one commit message. Here
is an example DCO Signed-off-by line in a commit message:
Describe your changes
Issue ticket number and link
Code checklist before requesting a review
PR Type
Bug fix, Enhancement
Description
Add pending packet buffer to handle flows with missing templates
Implement template learning detection and packet retry mechanism
Add configurable TTL and max packet limits for pending buffer
Extract packet processing logic into reusable method
Diagram Walkthrough
File Walkthrough
config.rs
Add pending packet buffer configuration optionsrust/netflow-collector/src/config.rs
pending_packet_ttl_secsconfiguration with default 60 secondsmax_pending_packetsconfiguration with default 100 packetslistener.rs
Implement pending packet buffer with template-triggered retryrust/netflow-collector/src/listener.rs
PendingPacketBufferfield to store packets awaiting templatestemplates_learnedatomic flag to track template learning eventsprocess_parsed_packet()methodretry_pending_packets()to re-parse buffered packets whentemplates arrive
sweep_pending_buffer()andget_pending_stats()public methodspending_buffer.rs
New pending packet buffer implementation with TTL managementrust/netflow-collector/src/pending_buffer.rs
PendingPacketBufferstruct managing per-sourcepacket queues
stats
metrics.rs
Add pending buffer metrics reportingrust/netflow-collector/src/metrics.rs
sweep_pending_buffer()during metrics reporting cyclemain.rs
Register pending buffer modulerust/netflow-collector/src/main.rs
pending_buffermodulepublisher.rs
Update test configuration for pending bufferrust/netflow-collector/src/publisher.rs
pending_packet_ttl_secsandmax_pending_packetsfields to testconfig
nats_creds_filefield from test configImported GitHub PR comment.
Original author: @CLAassistant
Original URL: https://github.com/carverauto/serviceradar/pull/2689#issuecomment-3844086650
Original created: 2026-02-03T22:32:51Z
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
mikemiles-dev seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2689#issuecomment-3844090063
Original created: 2026-02-03T22:33:24Z
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
Memory exhaustion
Description:
PendingPacketBuffercan grow without a global bound on number of sources (theHashMap<SocketAddr, ...>is unbounded), so an attacker can send malformed/templatedNetFlow from many (possibly spoofed) source addresses to trigger buffering and cause
memory exhaustion despite the per-source packet cap.
pending_buffer.rs [11-72]
Referred Code
🎫 No ticket provided
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status: Passed
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
Status: Passed
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status: Passed
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
Status:
Potential sensitive logs: Debug/warn logs include full parsed packet and per-flow fields (e.g.,
src_addr,dst_addr,ports) which may be considered sensitive and should be validated/redacted per the project
logging policy.
Referred Code
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2689#issuecomment-3844098743
Original created: 2026-02-03T22:34:46Z
PR Code Suggestions ✨
Latest suggestions up to
d3a5055Prevent duplicate flow replays
Modify the logic to buffer a raw datagram for retry only if none of its
contained packets could be processed, preventing potential data duplication.
rust/netflow-collector/src/listener.rs [232-256]
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a bug where successfully processed flows could be duplicated if other flows in the same datagram failed to parse, and provides a correct fix.
Avoid repeated mutex locking
Refactor the
retry_pending_packetsfunction to reduce repeated locking of thepending_buffermutex within the loop, improving performance and reducingcontention.
rust/netflow-collector/src/listener.rs [272-336]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a performance issue with repeated mutex locking inside a loop and proposes a more efficient pattern that reduces lock contention.
Remove racy pre-check locking
Remove the redundant
has_pendingcheck before callingretry_pending_packetstoavoid an unnecessary lock acquisition and a potential race condition.
rust/netflow-collector/src/listener.rs [259-266]
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly points out a redundant lock and a potential race condition, proposing a simplification that improves both performance and correctness.
Retry based on per-source success
Replace the global
templates_learnedatomic flag with a per-source success check(
!had_errors && has_pending) to trigger retries, avoiding race conditions andincorrect behavior with concurrent sources.
rust/netflow-collector/src/listener.rs [229-266]
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a race condition and flawed logic in using a global atomic flag for a per-source retry mechanism, proposing a more robust, localized trigger that improves correctness.
Prevent panics from poisoned locks
Replace
.unwrap()with proper error handling for theparsermutex lock toprevent the listener from panicking if the lock is poisoned.
rust/netflow-collector/src/listener.rs [224-227]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly points out that using
.unwrap()on a poisoned mutex will cause a panic, and proposes robust error handling consistent with other parts of the PR, improving application stability.Previous suggestions
Suggestions up to commit
0c38d9eLog retry errors instead of panicking
Add error handling for the result of
self.retry_pending_packets(peer_addr)tolog failures instead of allowing a potential panic.
rust/netflow-collector/src/listener.rs [250-252]
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that an unhandled
Resultfromretry_pending_packetscould cause a panic and proposes adding proper error handling, which is critical for service stability.Cap pending buffer by source
To prevent out-of-memory errors, add a cap on the number of distinct sources in
the pending buffer and evict the oldest source when the limit is reached.
rust/netflow-collector/src/pending_buffer.rs [11-39]
Suggestion importance[1-10]: 7
__
Why: The suggestion addresses a potential memory exhaustion issue by proposing a limit on the number of sources, which is a valid and important reliability improvement for the service.
Expose TTL to avoid unnecessary locking
Add a public
ttl()getter toPendingPacketBufferto avoid locking the bufferjust to read the
ttlvalue, allowing for more efficient expiration checks.rust/netflow-collector/src/pending_buffer.rs [54-56]
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that locking to read an immutable
ttlvalue is inefficient and proposes a getter to allow checking expiration outside the lock, which is a significant performance improvement.Imported GitHub PR review comment.
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2689#discussion_r2761440568
Original created: 2026-02-03T23:12:08Z
Original path: rust/netflow-collector/src/publisher.rs
Original line: 238
we dont need the nats_creds_file here anymore?
Imported GitHub PR comment.
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2689#issuecomment-3851408137
Original created: 2026-02-05T06:54:50Z
closing, stale
Pull request closed