fix: do not hold on to router thread handle until server exit (#2328)

* do not hold on to thread handle until server exit

* fix tests
This commit is contained in:
Thomas Linford 2023-04-13 10:02:07 +02:00 committed by GitHub
parent b40f5ef2ca
commit 7e207f4c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 26 deletions

View File

@ -20,7 +20,7 @@ use pty_writer::{pty_writer_main, PtyWriteInstruction};
use std::collections::{HashMap, HashSet};
use std::{
path::PathBuf,
sync::{Arc, Mutex, RwLock},
sync::{Arc, RwLock},
thread,
};
use zellij_utils::envs;
@ -260,8 +260,6 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
})
});
let thread_handles = Arc::new(Mutex::new(Vec::new()));
let _ = thread::Builder::new()
.name("server_listener".to_string())
.spawn({
@ -274,7 +272,6 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
let session_state = session_state.clone();
let to_server = to_server.clone();
let socket_path = socket_path.clone();
let thread_handles = thread_handles.clone();
move || {
drop(std::fs::remove_file(&socket_path));
let listener = LocalSocketListener::bind(&*socket_path).unwrap();
@ -291,22 +288,20 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
let session_data = session_data.clone();
let session_state = session_state.clone();
let to_server = to_server.clone();
thread_handles.lock().unwrap().push(
thread::Builder::new()
.name("server_router".to_string())
.spawn(move || {
route_thread_main(
session_data,
session_state,
os_input,
to_server,
receiver,
client_id,
)
.fatal()
})
.unwrap(),
);
thread::Builder::new()
.name("server_router".to_string())
.spawn(move || {
route_thread_main(
session_data,
session_state,
os_input,
to_server,
receiver,
client_id,
)
.fatal()
})
.unwrap();
},
Err(err) => {
panic!("err {:?}", err);
@ -642,11 +637,6 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
// Drop cached session data before exit.
*session_data.write().unwrap() = None;
thread_handles
.lock()
.unwrap()
.drain(..)
.for_each(|h| drop(h.join()));
drop(std::fs::remove_file(&socket_path));
}

View File

@ -2,7 +2,7 @@ use super::{Output, Tab};
use crate::panes::sixel::SixelImageStore;
use crate::screen::CopyOptions;
use crate::Arc;
use crate::Mutex;
use crate::{
os_input_output::{AsyncReader, Pid, ServerOsApi},
panes::PaneId,
@ -11,6 +11,8 @@ use crate::{
ClientId,
};
use std::path::PathBuf;
use std::sync::Mutex;
use zellij_utils::channels::Receiver;
use zellij_utils::data::Direction;
use zellij_utils::data::Resize;