mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-28 07:57:01 +00:00
fix(notify): close core notify correctness and safety gaps (#4502)
Land the remaining notify-crate audit fixes. backlog#979(b): remove_target now enforces the same bucket-binding guard as remove_target_config, refusing to delete a target still referenced by a bucket rule so notification rules are not left orphaned. backlog#984: - event.rs: an unversioned object omits versionId entirely instead of serializing versionId:"" (empty object/request versions treated as "no version"). - notifier.rs: RUSTFS_NOTIFY_SEND_CONCURRENCY=0 coerces back to the default instead of building a zero-permit semaphore that deadlocks every dispatch; init_bucket_targets_shared closes the replaced targets instead of dropping them without close() (connection leak). - subscriber_index.rs: store_snapshot uses an atomic compute_if_absent upsert, removing the get-then-insert TOCTOU that could clobber a concurrent first-writer's snapshot cell. - pipeline.rs: send_event assigns the history sequence and broadcasts to live subscribers under one critical section so broadcast order matches recorded sequence order. - xml_config.rs: filter value length is bounded by character count, not byte length, so valid multi-byte keys are no longer wrongly rejected. - global.rs: a losing initialize() race shuts the just-initialized system down instead of leaking its targets/replay workers. backlog#970 (notify part): reload_config stops the running replay workers before activating the new ones, so old and new workers do not concurrently drain the same persisted stores. The full signal+join shutdown lives in the targets crate under the same issue. Tests: added regression coverage for each fix. cargo build -p rustfs-notify, cargo test -p rustfs-notify --lib (98 passed), cargo clippy -p rustfs-notify --all-targets (clean). Relates to rustfs/backlog#979 Relates to rustfs/backlog#984 Relates to rustfs/backlog#970 Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
@@ -103,8 +103,18 @@ impl NotifyPipeline {
|
||||
}
|
||||
|
||||
pub async fn send_event(&self, event: Arc<Event>) {
|
||||
self.live_event_history.write().await.record(event.clone());
|
||||
let _ = self.live_event_sender.send(event.clone());
|
||||
// Assign the history sequence number and publish to live subscribers under
|
||||
// the *same* critical section. `record` allocates a monotonically increasing
|
||||
// sequence and `broadcast::Sender::send` is synchronous, so holding the write
|
||||
// guard across both guarantees the broadcast order matches the recorded
|
||||
// sequence order. Otherwise two concurrent senders could record seq 1 then 2
|
||||
// but broadcast 2 then 1, so a cursor-based consumer would observe events out
|
||||
// of order relative to the replayable history (backlog#984 / #969).
|
||||
{
|
||||
let mut history = self.live_event_history.write().await;
|
||||
history.record(event.clone());
|
||||
let _ = self.live_event_sender.send(event.clone());
|
||||
}
|
||||
self.notifier.send(event).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user