Ignore calls from non-existent threads

The thread might have died after sending the message, so
it might not exist by the time the server gets the message.
In that case, just ignore/drop the message.
This commit is contained in:
Ariel Abreu 2022-06-24 01:35:16 -04:00
parent 5bd9a87821
commit 2d5e25be35
No known key found for this signature in database
GPG Key ID: D67AE16CCEA85B70
3 changed files with 40 additions and 3 deletions

View File

@ -61,8 +61,14 @@ namespace DarlingServer {
_registeringWithLockHeld = true;
auto entry = entryFactory();
_registeringWithLockHeld = false;
if (!entry) {
return nullptr;
}
_map[entry->id()] = entry;
_nsmap[entry->nsid()] = entry;
return entry;
};

View File

@ -57,17 +57,48 @@ std::shared_ptr<DarlingServer::Call> DarlingServer::Call::callFromMessage(Messag
if ((header->number & DSERVER_CALL_UNMANAGED_FLAG) == 0) {
// now let's lookup (and possibly create) the process and thread making this call
process = processRegistry().registerIfAbsent(header->pid, [&]() {
auto tmp = std::make_shared<Process>(requestMessage.pid(), header->pid, static_cast<Process::Architecture>(header->architecture));
std::shared_ptr<Process> tmp = nullptr;
try {
tmp = std::make_shared<Process>(requestMessage.pid(), header->pid, static_cast<Process::Architecture>(header->architecture));
} catch (std::system_error e) {
return tmp;
}
Server::sharedInstance().monitorProcess(tmp);
return tmp;
});
if (!process) {
callLog.error() << "Received call from non-existent process?" << callLog.endLog;
// ignore this call
// TODO: instead of ignoring it, we should return a generic reply indicating `-ESRCH` or something like that.
return nullptr;
}
thread = threadRegistry().registerIfAbsent(header->tid, [&]() {
auto tmp = std::make_shared<Thread>(process, header->tid);
std::shared_ptr<Thread> tmp = nullptr;
try {
tmp = std::make_shared<Thread>(process, header->tid);
} catch (std::system_error e) {
return tmp;
}
tmp->setAddress(requestMessage.address());
tmp->registerWithProcess();
return tmp;
});
if (!thread) {
callLog.error() << "Received call from non-existent thread?" << callLog.endLog;
// ignore this call
// TODO: instead of ignoring it, we should return a generic reply indicating `-ESRCH` or something like that.
return nullptr;
}
thread->setAddress(requestMessage.address());
if (process->id() != requestMessage.pid()) {

View File

@ -142,7 +142,7 @@ DarlingServer::Thread::Thread(std::shared_ptr<Process> process, NSID nsid):
}
if (_tid == -1) {
throw std::runtime_error("Failed to find thread ID within darlingserver's namespace");
throw std::system_error(ESRCH, std::generic_category(), "Failed to find thread ID within darlingserver's namespace");
}
_stackSize = THREAD_STACK_SIZE;