diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 06c2b36..02c29f8 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -864,8 +864,9 @@ bool ConnectedClient::handleCommandFull(Command& cmd, bool disconnectOnFail) { if(generateReturnStatus) this->notifyError(result, cmd["return_code"].size() > 0 ? cmd["return_code"].first().as() : ""); - if(result.has_error() && this->state == ConnectionState::INIT_HIGH) + if(result.has_error() && this->state == ConnectionState::INIT_HIGH) { this->close_connection(system_clock::now()); //Disconnect now + } for (const auto& handler : postCommandHandler) handler(); diff --git a/server/src/client/voice/VoiceClient.cpp b/server/src/client/voice/VoiceClient.cpp index f493e45..6c1c0a4 100644 --- a/server/src/client/voice/VoiceClient.cpp +++ b/server/src/client/voice/VoiceClient.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "VoiceClient.h" #include "src/InstanceHandler.h" @@ -45,8 +46,10 @@ VoiceClient::~VoiceClient() { delete this->connection; this->connection = nullptr; - if(this->flushing_thread) + if(this->flushing_thread) { logCritical(this->getServerId(), "Deleting a VoiceClient which should still be hold within the flush thread!"); + this->flushing_thread->detach(); + } memtrack::freed(this); } @@ -185,7 +188,8 @@ bool VoiceClient::close_connection(const system_clock::time_point &timeout) { debugMessage(this->getServerId(), "{} Closing voice client connection. (Flush: {})", CLIENT_STR_LOG_PREFIX, flush); //TODO: Move this out into a thread pool? - this->flushing_thread = std::make_shared(THREAD_SAVE_OPERATIONS | THREAD_EXECUTE_LATER, [this, self_lock, timeout, flush]{ + + this->flushing_thread = std::make_shared([this, self_lock, timeout, flush]{ { /* Await that all commands have been processed. It does not make sense to unregister the client while command handling. */ std::lock_guard cmd_lock{this->command_lock}; @@ -219,7 +223,8 @@ bool VoiceClient::close_connection(const system_clock::time_point &timeout) { if(this->state > DISCONNECTING) /* it could happen that the client "reconnects" while flushing this shit */ this->finalDisconnect(); }); - flushing_thread->name("Flush thread VC").execute(); + + threads::name(*this->flushing_thread, "Flush thread VC"); return true; } @@ -239,7 +244,9 @@ void VoiceClient::finalDisconnect() { //Unload manager cache this->processLeave(); { - if(this->flushing_thread) this->flushing_thread->detach(); //The thread itself should be already done or executing this method + if(this->flushing_thread) { + this->flushing_thread->detach(); //The thread itself should be already done or executing this method + } this->flushing_thread.reset(); } if(this->voice_server) this->voice_server->unregisterConnection(ownLock); diff --git a/server/src/client/voice/VoiceClient.h b/server/src/client/voice/VoiceClient.h index 1a368d7..96ca26e 100644 --- a/server/src/client/voice/VoiceClient.h +++ b/server/src/client/voice/VoiceClient.h @@ -112,7 +112,7 @@ namespace ts { command_result handleCommandClientDisconnect(Command&); //Locked by finalDisconnect, disconnect and close connection - std::shared_ptr flushing_thread; + std::shared_ptr flushing_thread; ServerCommandExecutor server_command_executor_{this}; diff --git a/shared b/shared index 20f9295..d272089 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 20f9295fbe9eff9350b0ed5e8e6687514811501e +Subproject commit d2720897c4b168157e734a08b64680d636d29cb9