[ESI] Disallow calls on an unconnected `FuncService::Function` (#8779)

because currently, that'll result in segfaults.

Co-authored-by: Morten Borup Petersen <mpetersen@microsoft.com>
This commit is contained in:
Morten Borup Petersen 2025-07-25 11:01:59 +02:00 committed by GitHub
parent 2696da0895
commit d41ea14885
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -284,6 +284,7 @@ public:
std::mutex callMutex;
WriteChannelPort *arg;
ReadChannelPort *result;
bool connected = false;
};
private:

View File

@ -200,16 +200,21 @@ FuncService::Function *FuncService::Function::get(AppID id, BundleType *type,
}
void FuncService::Function::connect() {
if (connected)
throw std::runtime_error("Function is already connected");
if (channels.size() != 2)
throw std::runtime_error("FuncService must have exactly two channels");
arg = &getRawWrite("arg");
arg->connect();
result = &getRawRead("result");
result->connect();
connected = true;
}
std::future<MessageData>
FuncService::Function::call(const MessageData &argData) {
if (!connected)
throw std::runtime_error("Function must be 'connect'ed before calling");
std::scoped_lock<std::mutex> lock(callMutex);
arg->write(argData);
return result->readAsync();