mirror of
https://github.com/darlinghq/darlingserver.git
synced 2024-11-26 22:00:26 +00:00
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:
parent
5bd9a87821
commit
2d5e25be35
@ -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;
|
||||
};
|
||||
|
||||
|
35
src/call.cpp
35
src/call.cpp
@ -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()) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user