Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

revert missing retry and opt keep session (#9755)

21pages40e8f0d30764
diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart
index 099a04a15..a2ad96775 100644
--- a/flutter/lib/common.dart
+++ b/flutter/lib/common.dart
@@ -1174,33 +1174,21 @@ void msgBox(SessionID sessionId, String type, String title, String text,
dialogManager.dismissAll();
}));
}
- if (reconnect != null && title == "Connection Error") {
+ if (reconnect != null &&
+ title == "Connection Error" &&
+ reconnectTimeout != null) {
// `enabled` is used to disable the dialog button once the button is clicked.
final enabled = true.obs;
- final button = reconnectTimeout != null
- ? Obx(() => _ReconnectCountDownButton(
- second: reconnectTimeout,
- onPressed: enabled.isTrue
- ? () {
- // Disable the button
- enabled.value = false;
- reconnect(dialogManager, sessionId, false);
- }
- : null,
- ))
- : Obx(
- () => dialogButton(
- 'Reconnect',
- isOutline: true,
- onPressed: enabled.isTrue
- ? () {
- // Disable the button
- enabled.value = false;
- reconnect(dialogManager, sessionId, false);
- }
- : null,
- ),
- );
+ final button = Obx(() => _ReconnectCountDownButton(
+ second: reconnectTimeout,
+ onPressed: enabled.isTrue
+ ? () {
+ // Disable the button
+ enabled.value = false;
+ reconnect(dialogManager, sessionId, false);
+ }
+ : null,
+ ));
buttons.insert(0, button);
}
if (link.isNotEmpty) {
diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart
index 8bd0530f1..bd9194984 100644
--- a/flutter/lib/models/model.dart
+++ b/flutter/lib/models/model.dart
@@ -638,7 +638,7 @@ class FfiModel with ChangeNotifier {
{bool? hasCancel}) {
msgBox(sessionId, type, title, text, link, dialogManager,
hasCancel: hasCancel,
- reconnect: reconnect,
+ reconnect: hasRetry ? reconnect : null,
reconnectTimeout: hasRetry ? _reconnects : null);
_timer?.cancel();
if (hasRetry) {
diff --git a/src/server/connection.rs b/src/server/connection.rs
index 12157ddbb..c0cf8c784 100644
--- a/src/server/connection.rs
+++ b/src/server/connection.rs
@@ -760,10 +760,7 @@ impl Connection {
}
if let Err(err) = conn.try_port_forward_loop(&mut rx_from_cm).await {
conn.on_close(&err.to_string(), false).await;
- raii::AuthedConnID::remove_session_if_last_duplication(
- conn.inner.id(),
- conn.session_key(),
- );
+ raii::AuthedConnID::check_remove_session(conn.inner.id(), conn.session_key());
}
conn.post_conn_audit(json!({
@@ -2377,7 +2374,7 @@ impl Connection {
}
Some(misc::Union::CloseReason(_)) => {
self.on_close("Peer close", true).await;
- raii::AuthedConnID::remove_session_if_last_duplication(
+ raii::AuthedConnID::check_remove_session(
self.inner.id(),
self.session_key(),
);
@@ -3140,7 +3137,7 @@ impl Connection {
let mut msg_out = Message::new();
msg_out.set_misc(misc);
self.send(msg_out).await;
- raii::AuthedConnID::remove_session_if_last_duplication(self.inner.id(), self.session_key());
+ raii::AuthedConnID::check_remove_session(self.inner.id(), self.session_key());
}
fn read_dir(&mut self, dir: &str, include_hidden: bool) {
@@ -3295,17 +3292,6 @@ impl Connection {
}
}
- #[inline]
- fn conn_type(&self) -> AuthConnType {
- if self.file_transfer.is_some() {
- AuthConnType::FileTransfer
- } else if self.port_forward_socket.is_some() {
- AuthConnType::PortForward
- } else {
- AuthConnType::Remote
- }
- }
-
#[inline]
fn session_key(&self) -> SessionKey {
SessionKey {
@@ -3848,20 +3834,24 @@ mod raii {
.count()
}
- pub fn remove_session_if_last_duplication(conn_id: i32, key: SessionKey) {
+ pub fn check_remove_session(conn_id: i32, key: SessionKey) {
let mut lock = SESSIONS.lock().unwrap();
let contains = lock.contains_key(&key);
if contains {
- let another = AUTHED_CONNS
+ // If there are 2 connections with the same peer_id and session_id, a remote connection and a file transfer or port forward connection,
+ // If any of the connections is closed allowing retry, this will not be called;
+ // If the file transfer/port forward connection is closed with no retry, the session should be kept for remote control menu action;
+ // If the remote connection is closed with no retry, keep the session is not reasonable in case there is a retry button in the remote side, and ignore network fluctuations.
+ let another_remote = AUTHED_CONNS
.lock()
.unwrap()
.iter()
- .any(|c| c.0 != conn_id && c.2 == key);
- if !another {
- // Keep the session if there is another connection with same peer_id and session_id.
+ .any(|c| c.0 != conn_id && c.2 == key && c.1 == AuthConnType::Remote);
+ if !another_remote {
lock.remove(&key);
log::info!("remove session");
} else {
+ // Keep the session if there is another remote connection with same peer_id and session_id.
log::info!("skip remove session");
}
}