ssh remoting: Fix SSH connection not being closed (#18329)

This fixes the `SshSession` being leaked.

There were two leaks:

1. `Arc<SshSession>` itself got leaked into the `SettingsObserver` that
   lives as long as the application. Fixed with a weak reference.
2. The two tasks spawned by an `SshSession` had a circular dependency
   and didn't exit while the other one was running. Fixed by fixing (1)
   and then attaching one of the tasks to the `SshSession`, which means
   it gets dropped with the session itself, which leads the other task
   to error and exit.

Co-authored-by: Bennet <bennet@zed.dev>

Release Notes:

- N/A

---------

Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Thorsten Ball 2024-09-25 12:03:24 +02:00 committed by GitHub
parent 623a6eca75
commit 9d197ddc99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 53 additions and 15 deletions

View file

@ -334,17 +334,20 @@ impl SettingsObserver {
.log_err();
}
let weak_client = ssh.downgrade();
cx.observe_global::<SettingsStore>(move |_, cx| {
let new_settings = cx.global::<SettingsStore>().raw_user_settings();
if &settings != new_settings {
settings = new_settings.clone()
}
if let Some(content) = serde_json::to_string(&settings).log_err() {
ssh.send(proto::UpdateUserSettings {
project_id: 0,
content,
})
.log_err();
if let Some(ssh) = weak_client.upgrade() {
ssh.send(proto::UpdateUserSettings {
project_id: 0,
content,
})
.log_err();
}
}
})
.detach();