initial #2582
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!2582
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2582/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: #2158
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2158
Original created: 2025-12-16T19:48:30Z
Original updated: 2025-12-16T19:51:24Z
Original head: carverauto/serviceradar:2148-shallow-copies-of-hostresult-in-summary-collectionstream-cause-data-races
Original base: staging
Original merged: 2025-12-16T19:51:21Z by @mfreeman451
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
Description
Add
DeepCopyHostResult()helper to prevent data races from shallow copiesUpdate summary collection paths to use deep copies before releasing locks
Update memory store conversions to use deep copies for consistency
Add regression tests verifying concurrent read safety and no aliasing
Diagram Walkthrough
File Walkthrough
sweep.go
Add deep-copy helper for HostResultpkg/models/sweep.go
DeepCopyHostResult()function that creates non-aliased snapshotsof
HostResultPortResultsslice,PortMapmap, andICMPStatusstructPortMapentries reference the same copiedPortResultpointersas
PortResultsModeTCPconstant alignmentsweep_deepcopy_test.go
Add unit tests for deep-copy functionpkg/models/sweep_deepcopy_test.go
TestDeepCopyHostResult_NoAliasingPortResultsandPortMapreferencessummary_snapshot_test.go
Add regression and race detector testspkg/sweeper/summary_snapshot_test.go
TestGetSummary_HostResultsDoNotAliasInternalStateregression testICMPStatus,PortMap, andPortResultsTestGetSummary_ConcurrentReadsDoNotPanicrace detector testraces
base_processor.go
Use deep copies in summary collection pathspkg/sweeper/base_processor.go
collectShardSummaries()to useDeepCopyHostResult()whenappending hosts
processShardForSummary()to useDeepCopyHostResult()whenstreaming hosts
memory_store.go
Use deep copies in memory store conversionspkg/sweeper/memory_store.go
convertToSlice()to useDeepCopyHostResult()for consistencybuildSummary()to useDeepCopyHostResult()for consistencyInMemoryStoredefinitionproposal.md
Add change proposal documentationopenspec/changes/fix-sweeper-summary-shallow-copy/proposal.md
fields)
summary paths
summaries
spec.md
Add specification requirements for snapshot isolationopenspec/changes/fix-sweeper-summary-shallow-copy/specs/sweeper/spec.md
GetSummaryreturns safe-to-read host snapshotsHostResultvalues remain safe after locksreleased
tasks.md
Add implementation task checklistopenspec/changes/fix-sweeper-summary-shallow-copy/tasks.md
steps
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2158#issuecomment-3662125903
Original created: 2025-12-16T19:49:06Z
You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.🎫 #2148
HostResultincollectShardSummariesby ensuringreturned summary host data does not alias internal mutable fields (
PortResults,PortMap,ICMPStatus) after shard locks are released.HostResultinprocessShardForSummary/ summarystreaming by ensuring streamed
HostResultvalues do not alias internal mutable fieldsafter shard locks are released.
Process()updates (e.g.,adding ports) cannot race with callers reading summaries/streams.
(including race-detector coverage consistent with the reported failure scenario).
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: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
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
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/2158#issuecomment-3662129376
Original created: 2025-12-16T19:50:12Z
You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.
PR Code Suggestions ✨
Explore these optional code suggestions:
Simplify and correct deep copy logic
Refactor the
DeepCopyHostResultfunction to simplify the logic for copyingPortResultsandPortMap. First, copyPortResultsand track copied pointers.Then, copy
PortMap, reusing already copied pointers or creating new ones formap-only entries without modifying the
PortResultsslice.pkg/models/sweep.go [179-233]
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a bug in the new deep copy logic and proposes a cleaner, more robust implementation that fixes the bug and simplifies the code, improving correctness and maintainability.
Move channel sends outside lock
In
processShardForSummary, refactor the logic to first collect all deep-copiedhosts into a temporary slice while holding the read lock, then release the lock
before sending the hosts to the channel.
pkg/sweeper/base_processor.go [790-795]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a potential performance bottleneck by sending to a channel while holding a lock and proposes a good practice to release the lock sooner, improving concurrency.