From 648907ca8239f12444abc6538705cf4366d9014f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois-Simon=20Fauteux-Chapleau?=
 <francois-simon.fauteux-chapleau@savoirfairelinux.com>
Date: Tue, 6 Feb 2024 15:16:48 -0500
Subject: [PATCH] UPnPContext: fix deadlock during shutdown

GitLab: #19
Change-Id: Id8adf0faca9e575ce035d7e9a1cc5744d92ef635
---
 src/upnp/upnp_context.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/upnp/upnp_context.cpp b/src/upnp/upnp_context.cpp
index 6a7273e..0bbd282 100644
--- a/src/upnp/upnp_context.cpp
+++ b/src/upnp/upnp_context.cpp
@@ -112,6 +112,10 @@ UPnPContext::shutdown()
     } else {
         if (logger_) logger_->error("Shutdown timed-out");
     }
+    // NOTE: It's important to unlock mappingMutex_ here, otherwise we get a
+    // deadlock when the call to cv.wait_for() above times out before we return
+    // from proto->terminate() in shutdown(cv).
+    lk.unlock();
 
     if (ioContextRunner_) {
         if (logger_) logger_->debug("UPnPContext: stopping io_context thread {}", fmt::ptr(this));
-- 
GitLab