Skip to content

Commit

Permalink
Merge pull request #3585 from canonical/lxd-deadlock-quickfix
Browse files Browse the repository at this point in the history
LXD deadlock quickfix
  • Loading branch information
ricab committed Jul 19, 2024
1 parent 92b8adf commit 69c8a48
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/platform/backends/shared/base_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void mp::BaseVirtualMachine::check_state_for_shutdown(bool force)

std::string mp::BaseVirtualMachine::ssh_exec(const std::string& cmd, bool whisper)
{
const std::unique_lock lock{state_mutex};
std::unique_lock lock{state_mutex};

std::optional<std::string> log_details = std::nullopt;
bool reconnect = true;
Expand All @@ -235,7 +235,9 @@ std::string mp::BaseVirtualMachine::ssh_exec(const std::string& cmd, bool whispe
mpl::log(logging::Level::info, vm_name, msg);

reconnect = false; // once only
lock.unlock();
renew_ssh_session();
lock.lock();
}

try
Expand All @@ -258,8 +260,11 @@ std::string mp::BaseVirtualMachine::ssh_exec(const std::string& cmd, bool whispe

void mp::BaseVirtualMachine::renew_ssh_session()
{
if (!MP_UTILS.is_running(current_state())) // spend time updating state only if we need a new session
throw SSHException{fmt::format("SSH unavailable on instance {}: not running", vm_name)};
{
const std::unique_lock lock{state_mutex};
if (!MP_UTILS.is_running(current_state())) // spend time updating state only if we need a new session
throw SSHException{fmt::format("SSH unavailable on instance {}: not running", vm_name)};
}

mpl::log(logging::Level::debug,
vm_name,
Expand Down

0 comments on commit 69c8a48

Please sign in to comment.