Skip to content

Commit eb069ab

Browse files
committed
Fix crash on simultaneous IPC calls using the same thread
This error occurs when non-libmultiprocess clients make simultaenous IPC calls to the server using the same Server thread. The libmultiprocess Cpp client ensures a 1-to-1 mapping of client-to-server threads, so simultaneous calls using the same thread cannot be made.
1 parent 47d79db commit eb069ab

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/mp/proxy-io.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,13 @@ struct Waiter
281281
Waiter() = default;
282282

283283
template <typename Fn>
284-
void post(Fn&& fn)
284+
bool post(Fn&& fn)
285285
{
286286
const Lock lock(m_mutex);
287-
assert(!m_fn);
287+
if (m_fn) return false;
288288
m_fn = std::forward<Fn>(fn);
289289
m_cv.notify_all();
290+
return true;
290291
}
291292

292293
template <class Predicate>

include/mp/type-context.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
152152
const auto& thread = static_cast<ProxyServer<Thread>&>(*thread_server);
153153
server.m_context.loop->log()
154154
<< "IPC server post request #" << req << " {" << thread.m_thread_context.thread_name << "}";
155-
thread.m_thread_context.waiter->post(std::move(invoke));
155+
if (!thread.m_thread_context.waiter->post(std::move(invoke))) {
156+
server.m_context.loop->log()
157+
<< "IPC server error request #" << req
158+
<< " {" << thread.m_thread_context.thread_name << "}" << ", thread busy";
159+
throw std::runtime_error("thread busy");
160+
}
156161
} else {
157162
server.m_context.loop->log()
158163
<< "IPC server error request #" << req << ", missing thread to execute request";

0 commit comments

Comments
 (0)