Skip to content

Commit e4dec96

Browse files
committed
io_uring: fix shared config access deadlock by using cloned struct
Problem occured when doing some change from web interface
1 parent fa4807c commit e4dec96

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/io_uring.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,15 @@ pub async fn io_loop(
207207
// prepare/bind needed TCP listeners
208208
let mut dhu_listener = None;
209209
let mut md_listener = None;
210-
if !config.read().await.wired.is_some() {
210+
let shared_config = config.clone();
211+
let config = config.read().await.clone();
212+
if !config.wired.is_some() {
211213
info!("{} 🛰️ Starting TCP server for MD...", NAME);
212214
let bind_addr = format!("0.0.0.0:{}", TCP_SERVER_PORT).parse().unwrap();
213215
md_listener = Some(TcpListener::bind(bind_addr).unwrap());
214216
info!("{} 🛰️ MD TCP server bound to: <u>{}</u>", NAME, bind_addr);
215217
}
216-
if config.read().await.dhu {
218+
if config.dhu {
217219
info!("{} 🛰️ Starting TCP server for DHU...", NAME);
218220
let bind_addr = format!("0.0.0.0:{}", TCP_DHU_PORT).parse().unwrap();
219221
dhu_listener = Some(TcpListener::bind(bind_addr).unwrap());
@@ -225,12 +227,12 @@ pub async fn io_loop(
225227
let mut md_usb = None;
226228
let mut hu_tcp = None;
227229
let mut hu_usb = None;
228-
if config.read().await.wired.is_some() {
230+
if config.wired.is_some() {
229231
info!(
230232
"{} 💤 trying to enable Android Auto mode on USB port...",
231233
NAME
232234
);
233-
match usb_stream::new(config.read().await.wired.clone()).await {
235+
match usb_stream::new(config.wired.clone()).await {
234236
Err(e) => {
235237
error!("{} 🔴 Enabling Android Auto: {}", NAME, e);
236238
// notify main loop to restart
@@ -258,7 +260,7 @@ pub async fn io_loop(
258260
}
259261
}
260262

261-
if config.read().await.dhu {
263+
if config.dhu {
262264
info!(
263265
"{} 🛰️ DHU TCP server: listening for `Desktop Head Unit` connection...",
264266
NAME
@@ -347,11 +349,11 @@ pub async fn io_loop(
347349
// handling battery in JSON
348350
let mut rest_server_handle = None;
349351
let mut rest_ctx = None;
350-
if config.read().await.mitm && config.read().await.ev {
352+
if config.mitm && config.ev {
351353
let ctx = RestContext {
352354
sensor_channel: None,
353-
ev_battery_capacity: config.read().await.ev_battery_capacity,
354-
ev_factor: config.read().await.ev_factor,
355+
ev_battery_capacity: config.ev_battery_capacity,
356+
ev_factor: config.ev_factor,
355357
};
356358
let ctx = Arc::new(Mutex::new(ctx));
357359

@@ -391,7 +393,7 @@ pub async fn io_loop(
391393
file_bytes,
392394
stream_bytes,
393395
read_timeout,
394-
config.clone(),
396+
shared_config.clone(),
395397
));
396398

397399
// Stop as soon as one of them errors
@@ -421,7 +423,7 @@ pub async fn io_loop(
421423
handle.abort();
422424
}
423425
// stop EV battery logger if neded
424-
if let Some(ref path) = config.read().await.ev_battery_logger {
426+
if let Some(ref path) = config.ev_battery_logger {
425427
let _ = Command::new(path).arg("stop").spawn();
426428
}
427429

0 commit comments

Comments
 (0)