File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -648,7 +648,7 @@ PUPnP::requestMappingRemove(const Mapping& mapping)
648648 asio::post (*ioContext, [w = weak (), mapping] {
649649 if (auto upnpThis = w.lock ()) {
650650 // Abort if we are shutting down.
651- if (not upnpThis->isRunning () )
651+ if (not upnpThis->clientRegistered_ )
652652 return ;
653653 if (upnpThis->actionDeletePortMapping (mapping)) {
654654 upnpThis->processRemoveMapAction (mapping);
Original file line number Diff line number Diff line change @@ -98,6 +98,14 @@ UPnPContext::shutdown(std::condition_variable& cv)
9898
9999 stopUpnp (true );
100100
101+ std::promise<void > ioFlushed;
102+ asio::post (*ioCtx, [&ioFlushed] { ioFlushed.set_value (); });
103+ auto status = ioFlushed.get_future ().wait_for (std::chrono::seconds (5 ));
104+ if (status == std::future_status::timeout) {
105+ if (logger_)
106+ logger_->warn (" Timed out waiting for pending UPnP operations to complete" );
107+ }
108+
101109 for (auto const & [_, proto] : protocolList_) {
102110 proto->terminate ();
103111 }
@@ -224,8 +232,6 @@ UPnPContext::stopUpnp(bool forceRelease)
224232 toRemoveList.emplace_back (map);
225233 }
226234 }
227- // Invalidate the current IGD.
228- currentIgd_.reset ();
229235 }
230236 for (auto const & map : toRemoveList) {
231237 requestRemoveMapping (map);
@@ -238,6 +244,11 @@ UPnPContext::stopUpnp(bool forceRelease)
238244 unregisterMapping (map);
239245 }
240246 }
247+ {
248+ // Invalidate the current IGD.
249+ std::lock_guard lock (mappingMutex_);
250+ currentIgd_.reset ();
251+ }
241252
242253 // Clear all current IGDs.
243254 for (auto const & [_, protocol] : protocolList_) {
You can’t perform that action at this time.
0 commit comments