Skip to content

Commit b06f779

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 308d6a2 commit b06f779

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
@@ -125,19 +125,19 @@ impl ListenersManager {
125125
let listener_name = listener.get_name();
126126
let (addr, dev) = listener.get_socket();
127127
info!("Listener {} at {addr} (device bind:{})", listener_name, dev.is_some());
128+
129+
// Stop the old listener if it exists before starting a new one
130+
if self.listener_handles.contains_key(&listener_name) {
131+
self.stop_listener(&listener_name)?;
132+
#[cfg(debug_assertions)]
133+
debug!("Listener {listener_name} already exists, stopping and replacing it");
134+
}
135+
128136
// spawn the task for this listener address, this will spawn additional task per connection
129137
let join_handle = tokio::spawn(async move {
130138
let error = listener.start().await;
131139
warn!("Listener {listener_name} exited: {error}");
132140
});
133-
#[cfg(debug_assertions)]
134-
if self.listener_handles.contains_key(&listener_name) {
135-
debug!("Listener {listener_name} already exists, replacing it");
136-
}
137-
// note: join handle gets overwritten here if it already exists.
138-
// handles are abort on drop so will be aborted, closing the socket
139-
// but the any tasks spawned within this task, which happens on a per-connection basis,
140-
// will survive past this point and only get dropped when their session ends
141141
self.listener_handles.insert(listener_name, ListenerInfo::new(join_handle, listener_conf));
142142

143143
Ok(())

0 commit comments

Comments
 (0)