Skip to content

Commit df805b6

Browse files
committed
listeners: fix duplicate listener names by stopping existing listener
- Check if listener with same name exists before starting new one - Stop the existing listener to prevent conflicts - Improve logging for duplicate listener detection Signed-off-by: Eeshu-Yadav <[email protected]>
1 parent f053e56 commit df805b6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

orion-lib/src/listeners/listeners_manager.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ impl ListenersManager {
122122
let listener_name = listener.get_name();
123123
let (addr, dev) = listener.get_socket();
124124
info!("Listener {} at {addr} (device bind:{})", listener_name, dev.is_some());
125+
126+
// Stop the old listener if it exists before starting a new one
127+
if self.listener_handles.contains_key(&listener_name) {
128+
self.stop_listener(&listener_name)?;
129+
#[cfg(debug_assertions)]
130+
debug!("Listener {listener_name} already exists, stopping and replacing it");
131+
}
132+
125133
// spawn the task for this listener address, this will spawn additional task per connection
126134
let join_handle = tokio::spawn(async move {
127135
let error = listener.start().await;
128136
warn!("Listener {listener_name} exited: {error}");
129137
});
130-
#[cfg(debug_assertions)]
131-
if self.listener_handles.contains_key(&listener_name) {
132-
debug!("Listener {listener_name} already exists, replacing it");
133-
}
134-
// note: join handle gets overwritten here if it already exists.
135-
// handles are abort on drop so will be aborted, closing the socket
136-
// but the any tasks spawned within this task, which happens on a per-connection basis,
137-
// will survive past this point and only get dropped when their session ends
138138
self.listener_handles.insert(listener_name, ListenerInfo::new(join_handle, listener_conf));
139139

140140
Ok(())

0 commit comments

Comments
 (0)