Skip to content

Commit

Permalink
add timeout to RustConnection::connect to X11 server
Browse files Browse the repository at this point in the history
  • Loading branch information
jonZlotnik authored and complexspaces committed Apr 23, 2023
1 parent f24df29 commit efedfb9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/platform/linux/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use std::{
collections::{hash_map::Entry, HashMap},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
mpsc, Arc,
},
thread::JoinHandle,
thread::{self, JoinHandle},
thread_local,
time::{Duration, Instant},
usize,
Expand Down Expand Up @@ -134,8 +134,14 @@ struct Inner {
impl XContext {
fn new() -> Result<Self> {
// create a new connection to an X11 server
let (conn, screen_num): (RustConnection, _) =
RustConnection::connect(None).map_err(into_unknown)?;
// with a timeout on connecting to the socket in case of hangage
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
tx.send(RustConnection::connect(None)).ok(); // disregard error sending on channel as main thread has timed out.
});
let patient_conn = rx.recv_timeout(SHORT_TIMEOUT_DUR).map_err(into_unknown)?;
let (conn, screen_num): (RustConnection, _) = patient_conn.map_err(into_unknown)?;

let screen = conn
.setup()
.roots
Expand Down

0 comments on commit efedfb9

Please sign in to comment.