An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.
Rust androidanydeskdartflatpakflutterflutter-appsioslinuxmacosp2prdpremote-controlremote-desktoprustrust-langteamviewervncwaylandwindows
Fix/tcp websocket error propagation (#16946)
fufesoube181a9d1824
diff --git a/libs/hbb_common b/libs/hbb_commonindex fae47e024..450cc1d7b 160000--- a/libs/hbb_common+++ b/libs/hbb_common@@ -1 +1 @@-Subproject commit fae47e024dd83cef6aaecde0aa7d11731df11649+Subproject commit 450cc1d7b729cfa8d19b5a7527c9cc2fe54cf5ebdiff --git a/src/platform/macos.rs b/src/platform/macos.rsindex 4d7705d38..3b553be2d 100644--- a/src/platform/macos.rs+++ b/src/platform/macos.rs@@ -140,6 +140,14 @@ pub fn major_version() -> u32 {unsafe { majorVersion() }}+pub(crate) fn is_host_unreachable_error(err: &hbb_common::anyhow::Error) -> bool {+ err.chain().any(|cause| {+ cause+ .downcast_ref::<std::io::Error>()+ .is_some_and(|err| err.raw_os_error() == Some(hbb_common::libc::EHOSTUNREACH))+ })+}+pub fn is_process_trusted(prompt: bool) -> bool {autoreleasepool(|| unsafe_is_process_trusted(prompt))}@@ -2155,6 +2163,35 @@ pub(crate) fn get_bundle_id() -> Option<String> {}}+#[cfg(test)]+mod network_error_tests {+ use super::is_host_unreachable_error;+ use hbb_common::{anyhow, libc, thiserror};+ use std::io;++ #[derive(Debug, thiserror::Error)]+ #[error("transport error: {0}")]+ struct TransportError(#[source] io::Error);++ #[test]+ fn host_unreachable_matches_direct_and_context_errors() {+ for (code, expected) in [(libc::EHOSTUNREACH, true), (libc::ECONNREFUSED, false)] {+ let err = anyhow::Error::new(io::Error::from_raw_os_error(code));+ assert_eq!(is_host_unreachable_error(&err), expected);+ assert_eq!(is_host_unreachable_error(&err.context("connect")), expected);+ }+ }++ #[test]+ fn host_unreachable_matches_nested_sources() {+ for (code, expected) in [(libc::EHOSTUNREACH, true), (libc::ECONNREFUSED, false)] {+ let err = anyhow::Error::new(TransportError(io::Error::from_raw_os_error(code)))+ .context("connect");+ assert_eq!(is_host_unreachable_error(&err), expected);+ }+ }+}+#[cfg(test)]mod update_tests {use super::*;diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rsindex 7e7ea5f0c..df9817a5a 100644--- a/src/rendezvous_mediator.rs+++ b/src/rendezvous_mediator.rs@@ -39,6 +39,8 @@ use crate::{type Message = RendezvousMessage;+const FAST_RETRY_TIMEOUT: u64 = 3_000;+fn connection_meta(control_permissions: Option<ControlPermissions>,controlled_context: Option<ControlledContext>,@@ -357,13 +359,18 @@ impl RendezvousMediator {let timeout = timeout.clone();futs.push(tokio::spawn(async move {if let Err(err) = Self::start(server, host).await {+ #[cfg(target_os = "macos")]+ if crate::platform::is_host_unreachable_error(&err) {+ // An app update can briefly invalidate its Local Network policy.+ *timeout.write().unwrap() = FAST_RETRY_TIMEOUT;+ }let err = format!("rendezvous mediator error: {err}");// When user reboot, there might be below error, waiting too long// (CONNECT_TIMEOUT 18s) will make user think there is bugif err.contains("10054") || err.contains("11001") {// No such host is known. (os error 11001)// An existing connection was forcibly closed by the remote host. (os error 10054): also happens for UDP- *timeout.write().unwrap() = 3000;+ *timeout.write().unwrap() = FAST_RETRY_TIMEOUT;}log::error!("{err}");}@@ -1710,7 +1717,7 @@ whereOk(stream) => return Some(stream),// Not logged one by one, but the count says which gateway it was: RST fails a// punch at once and fits a dozen into the window, a silent drop holds the one- // punch for the whole of it. `connect_tcp_local` keeps no errno anyway.+ // punch for the whole of it.Err(_) => round += 1,}}