Skip to content

Commit 7363191

Browse files
fix(host): ensure config sender is not dropped
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
1 parent 1592e7d commit 7363191

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/host/src/wasmbus/config.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub struct ConfigBundle {
5656
///
5757
/// These are `drop()`ed when the bundle is dropped
5858
_handles: Arc<AbortHandles>,
59+
/// The sender that is used to notify the receiver that the config has changed, this
60+
/// must not be dropped until the receiver is dropped so we ensure it's kept alive
61+
_changed_notifier: Arc<Sender<()>>,
5962
}
6063

6164
impl Clone for ConfigBundle {
@@ -69,6 +72,7 @@ impl Clone for ConfigBundle {
6972
merged_config: self.merged_config.clone(),
7073
config_names: self.config_names.clone(),
7174
changed_receiver,
75+
_changed_notifier: self._changed_notifier.clone(),
7276
_handles: self._handles.clone(),
7377
}
7478
}
@@ -98,17 +102,18 @@ impl ConfigBundle {
98102
.unzip();
99103
// Now that we've set initial config, create the bundle and update the merged config with the latest values
100104
let (changed_notifier, changed_receiver) = watch::channel(());
105+
let changed_notifier = Arc::new(changed_notifier);
101106
let mut bundle = ConfigBundle {
102107
merged_config: Arc::default(),
103108
config_names: receivers.iter().map(|r| r.name.clone()).collect(),
104109
changed_receiver,
110+
_changed_notifier: changed_notifier.clone(),
105111
_handles: Arc::new(AbortHandles {
106112
handles: abort_handles,
107113
}),
108114
};
109115
let ordered_configs: Arc<Vec<Receiver<HashMap<String, String>>>> =
110116
Arc::new(receivers.iter().map(|r| r.receiver.clone()).collect());
111-
let changed_notifier = Arc::new(changed_notifier);
112117
update_merge(&bundle.merged_config, &changed_notifier, &ordered_configs).await;
113118
// Move all the receivers into spawned tasks to update the config
114119
for ConfigReceiver { name, mut receiver } in receivers {

0 commit comments

Comments
 (0)