-
Notifications
You must be signed in to change notification settings - Fork 23
fix: three-layer protection against unbounded snapshot growth #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,8 +290,25 @@ size_t InMemoryFaultStorage::check_time_based_confirmation(const rclcpp::Time & | |
| return confirmed_count; | ||
| } | ||
|
|
||
| void InMemoryFaultStorage::set_max_snapshots_per_fault(size_t max_count) { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| max_snapshots_per_fault_ = max_count; | ||
| } | ||
|
|
||
| void InMemoryFaultStorage::store_snapshot(const SnapshotData & snapshot) { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| if (max_snapshots_per_fault_ > 0) { | ||
| size_t count = 0; | ||
| for (const auto & s : snapshots_) { | ||
| if (s.fault_code == snapshot.fault_code) { | ||
| ++count; | ||
| } | ||
| } | ||
| if (count >= max_snapshots_per_fault_) { | ||
bburda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Silent rejection: storage layer has no logger. Callers should log if needed. | ||
| return; // Reject new - keep first N inserted snapshots | ||
| } | ||
| } | ||
| snapshots_.push_back(snapshot); | ||
| } | ||
bburda marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
298
to
313
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FaultStorageis a public abstract interface, and adding a new pure-virtual method (set_max_snapshots_per_fault) is a source/ABI breaking change for any downstream storage implementations. If backwards compatibility matters, consider providing a default no-op implementation in the base class (non-pure virtual), or bump the relevant version / clearly mark this as a breaking change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed - changed to virtual with default no-op to avoid breaking downstream.