|
18 | 18 | use std::collections::BTreeMap; |
19 | 19 |
|
20 | 20 | use tokio::sync::{broadcast, mpsc}; |
21 | | -use tracing::{debug, info, warn}; |
| 21 | +use tracing::{info, warn}; |
22 | 22 |
|
23 | 23 | use orion_configuration::config::{ |
24 | 24 | network_filters::http_connection_manager::RouteConfiguration, Listener as ListenerConfig, |
@@ -122,19 +122,18 @@ impl ListenersManager { |
122 | 122 | let listener_name = listener.get_name(); |
123 | 123 | let (addr, dev) = listener.get_socket(); |
124 | 124 | info!("Listener {} at {addr} (device bind:{})", listener_name, dev.is_some()); |
| 125 | + |
| 126 | + // Stop existing listener if one exists with the same name to prevent mixed responses |
| 127 | + if self.listener_handles.contains_key(&listener_name) { |
| 128 | + info!("Listener {listener_name} already exists, stopping existing listener before starting new one"); |
| 129 | + self.stop_listener(&listener_name)?; |
| 130 | + } |
| 131 | + |
125 | 132 | // spawn the task for this listener address, this will spawn additional task per connection |
126 | 133 | let join_handle = tokio::spawn(async move { |
127 | 134 | let error = listener.start().await; |
128 | 135 | warn!("Listener {listener_name} exited: {error}"); |
129 | 136 | }); |
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 |
138 | 137 | self.listener_handles.insert(listener_name, ListenerInfo::new(join_handle, listener_conf)); |
139 | 138 |
|
140 | 139 | Ok(()) |
@@ -193,10 +192,8 @@ mod tests { |
193 | 192 | man.start_listener(l2, l2_info).unwrap(); |
194 | 193 | assert!(routeb_tx2.send(RouteConfigurationChange::Removed("n/a".into())).is_ok()); |
195 | 194 | tokio::task::yield_now().await; |
196 | | - |
197 | | - // This should fail because the old listener exited already dropping the rx |
| 195 | + // The first listener should now be stopped, so this should fail |
198 | 196 | assert!(routeb_tx1.send(RouteConfigurationChange::Removed("n/a".into())).is_err()); |
199 | | - // Yield once more just in case more logs can be seen |
200 | 197 | tokio::task::yield_now().await; |
201 | 198 | } |
202 | 199 |
|
|
0 commit comments