summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-04-19 17:33:30 +0200
committerAram Drevekenin <aram@poor.dev>2024-04-19 17:33:30 +0200
commit3629532e4dea147a9969c46668005b9ea2eb6d0e (patch)
tree3d673f297cf299dffe3f41af4e34420e24ce53ca
parent07dddc60fc1ba5fb29a5f0b6331f381990a8420d (diff)
fix(router): deadlock when unblocking input threadfix-session-freeze
-rw-r--r--zellij-server/src/lib.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs
index e1244ec4a..55c98e58d 100644
--- a/zellij-server/src/lib.rs
+++ b/zellij-server/src/lib.rs
@@ -264,6 +264,9 @@ impl SessionState {
pub fn client_ids(&self) -> Vec<ClientId> {
self.clients.keys().copied().collect()
}
+ pub fn get_pipe(&self, pipe_name: &str) -> Option<ClientId> {
+ self.pipes.get(pipe_name).copied()
+ }
pub fn active_clients_are_connected(&self) -> bool {
let ids_of_pipe_clients: HashSet<ClientId> = self.pipes.values().copied().collect();
let mut active_clients_connected = false;
@@ -516,9 +519,10 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
);
},
ServerInstruction::UnblockInputThread => {
- for client_id in session_state.read().unwrap().clients.keys() {
+ let client_ids = session_state.read().unwrap().client_ids();
+ for client_id in client_ids {
send_to_client!(
- *client_id,
+ client_id,
os_input,
ServerToClientMsg::UnblockInputThread,
session_state
@@ -526,10 +530,11 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
}
},
ServerInstruction::UnblockCliPipeInput(pipe_name) => {
- match session_state.read().unwrap().pipes.get(&pipe_name) {
+ let pipe = session_state.read().unwrap().get_pipe(&pipe_name);
+ match pipe {
Some(client_id) => {
send_to_client!(
- *client_id,
+ client_id,
os_input,
ServerToClientMsg::UnblockCliPipeInput(pipe_name.clone()),
session_state
@@ -537,9 +542,10 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
},
None => {
// send to all clients, this pipe might not have been associated yet
- for client_id in session_state.read().unwrap().clients.keys() {
+ let client_ids = session_state.read().unwrap().client_ids();
+ for client_id in client_ids {
send_to_client!(
- *client_id,
+ client_id,
os_input,
ServerToClientMsg::UnblockCliPipeInput(pipe_name.clone()),
session_state
@@ -549,10 +555,11 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
}
},
ServerInstruction::CliPipeOutput(pipe_name, output) => {
- match session_state.read().unwrap().pipes.get(&pipe_name) {
+ let pipe = session_state.read().unwrap().get_pipe(&pipe_name);
+ match pipe {
Some(client_id) => {
send_to_client!(
- *client_id,
+ client_id,
os_input,
ServerToClientMsg::CliPipeOutput(pipe_name.clone(), output.clone()),
session_state
@@ -560,9 +567,10 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
},
None => {
// send to all clients, this pipe might not have been associated yet
- for client_id in session_state.read().unwrap().clients.keys() {
+ let client_ids = session_state.read().unwrap().client_ids();
+ for client_id in client_ids {
send_to_client!(
- *client_id,
+ client_id,
os_input,
ServerToClientMsg::CliPipeOutput(pipe_name.clone(), output.clone()),
session_state