Some minor and small fixes

This commit is contained in:
WolverinDEV 2020-12-05 16:27:41 +01:00
parent 1c99f093c8
commit f2e5387318
4 changed files with 15 additions and 7 deletions

View File

@ -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<std::string>() : "");
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();

View File

@ -6,6 +6,7 @@
#include <misc/endianness.h>
#include <misc/memtracker.h>
#include <log/LogUtils.h>
#include <ThreadPool/ThreadHelper.h>
#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<VoiceClient>(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<threads::Thread>(THREAD_SAVE_OPERATIONS | THREAD_EXECUTE_LATER, [this, self_lock, timeout, flush]{
this->flushing_thread = std::make_shared<std::thread>([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);

View File

@ -112,7 +112,7 @@ namespace ts {
command_result handleCommandClientDisconnect(Command&);
//Locked by finalDisconnect, disconnect and close connection
std::shared_ptr<threads::Thread> flushing_thread;
std::shared_ptr<std::thread> flushing_thread;
ServerCommandExecutor server_command_executor_{this};

2
shared

@ -1 +1 @@
Subproject commit 20f9295fbe9eff9350b0ed5e8e6687514811501e
Subproject commit d2720897c4b168157e734a08b64680d636d29cb9