From 31f79abb531b5382fd1eb296ff068b56f3ab83d0 Mon Sep 17 00:00:00 2001 From: adeci Date: Sat, 7 Jun 2025 04:39:33 -0400 Subject: [PATCH 1/2] bugfix for persistent loginctl sessions --- pkgs/clan-cli/clan_lib/ssh/remote.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_lib/ssh/remote.py b/pkgs/clan-cli/clan_lib/ssh/remote.py index 6f9cc677e..0517d1901 100644 --- a/pkgs/clan-cli/clan_lib/ssh/remote.py +++ b/pkgs/clan-cli/clan_lib/ssh/remote.py @@ -111,7 +111,7 @@ class Remote: ): directory = "/tmp/" with TemporaryDirectory(prefix="clan-ssh", dir=directory) as temp_dir: - yield Remote( + remote = Remote( address=self.address, user=self.user, command_prefix=self.command_prefix, @@ -126,6 +126,25 @@ class Remote: _control_path_dir=Path(temp_dir), _askpass_path=self._askpass_path, ) + try: + yield remote + finally: + # Terminate the SSH master connection + socket_path = Path(temp_dir) / "socket" + if socket_path.exists(): + try: + exit_cmd = [ + "ssh", + "-o", + f"ControlPath={socket_path}", + "-O", + "exit", + ] + exit_cmd.append(remote.target) + subprocess.run(exit_cmd, capture_output=True, timeout=5) + except (subprocess.TimeoutExpired, subprocess.CalledProcessError): + # If exit fails still try to stop the master connection + pass @contextmanager def become_root(self) -> Iterator["Remote"]: From 35a7bbf5d848ded257ad4ad4527ae940996ec009 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 11 Jun 2025 14:39:50 +0200 Subject: [PATCH 2/2] clan-cli: reduce ssh controlmaster timeout to 1min --- pkgs/clan-cli/clan_lib/ssh/remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_lib/ssh/remote.py b/pkgs/clan-cli/clan_lib/ssh/remote.py index 0517d1901..3ae37e0fc 100644 --- a/pkgs/clan-cli/clan_lib/ssh/remote.py +++ b/pkgs/clan-cli/clan_lib/ssh/remote.py @@ -309,7 +309,7 @@ class Remote: "-o", "ControlMaster=auto", "-o", - "ControlPersist=30m", + "ControlPersist=1m", "-o", f"ControlPath={socket_path}", ]