[ntcore] Don't deadlock server on early destroy (#4863)

It was possible to deadlock on instance destroy if the server had started
but had not yet fully initialized its handles.
This commit is contained in:
Peter Johnson
2022-12-27 10:25:48 -08:00
committed by GitHub
parent 2ac41f3edc
commit 6cfe5de00d
2 changed files with 17 additions and 5 deletions

View File

@@ -113,12 +113,15 @@ void InstanceImpl::StartServer(std::string_view persistFilename,
}
void InstanceImpl::StopServer() {
std::scoped_lock lock{m_mutex};
if ((networkMode & NT_NET_MODE_SERVER) == 0) {
return;
std::shared_ptr<NetworkServer> server;
{
std::scoped_lock lock{m_mutex};
if ((networkMode & NT_NET_MODE_SERVER) == 0) {
return;
}
server = std::move(m_networkServer);
networkMode = NT_NET_MODE_NONE;
}
m_networkServer.reset();
networkMode = NT_NET_MODE_NONE;
}
void InstanceImpl::StartClient3(std::string_view identity) {