Skip to content

Commit

Permalink
[wpinet] Leak multicast handles during windows shutdown (#5550)
Browse files Browse the repository at this point in the history
Destructing either of the multicast objects during process shutdown will result in a crash due to attempting to start a task on the non-existent thread pool.

Solve this by just leaking all the handles upon destruction of the static multicast manager. This won't solve the case where the user statically allocates the object, but solves Java and C access, and most cases wouldn't be statically allocating the service announcer anyway in C++.
  • Loading branch information
ThadHouse authored Aug 19, 2023
1 parent f9e2757 commit 7a2d336
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wpinet/src/main/native/cpp/MulticastHandleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ MulticastHandleManager& wpi::GetMulticastManager() {
static MulticastHandleManager manager;
return manager;
}

#ifdef _WIN32
MulticastHandleManager::~MulticastHandleManager() {
// Multicast handles cannot be safely destructed on windows during shutdown.
// Just leak all handles.
for (auto&& i : resolvers) {
i.second.release();
}

for (auto&& i : announcers) {
i.second.release();
}
}
#endif
3 changes: 3 additions & 0 deletions wpinet/src/main/native/cpp/MulticastHandleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ struct MulticastHandleManager {
resolvers;
wpi::DenseMap<size_t, std::unique_ptr<wpi::MulticastServiceAnnouncer>>
announcers;
#ifdef _WIN32
~MulticastHandleManager();
#endif
};

MulticastHandleManager& GetMulticastManager();
Expand Down

0 comments on commit 7a2d336

Please sign in to comment.