Review report

core: PR #36572

1 minor finding

Findings

Link

[minor] · loopRef() can dereference a disengaged event-loop queue

If the parent disconnects while the child makes an IPC call, loopRef() can reach undefined behavior during shutdown; no concrete production impact was identified, and the same race was already unsafe before this change.

Location: src/ipc/capnp/protocol.cpp:184 (head).

Details and suggested fix

In serve mode, EventLoop::loop() resets m_async_fns under m_mutex just before returning. serve() resets m_loop afterward under m_loop_mutex. A call to loopRef() in between can see an engaged m_loop, acquire m_mutex, and call done(). With zero references, done() evaluates m_async_fns->empty() even though the optional is disengaged. This is undefined behavior: assertion or hardened builds abort, while other builds may read stale storage.

The conditional path is an IPC call made by the child while the parent disconnects. For example, the hidden echoipc RPC can reach loopRef() through spawnProcess(), makeStream(), and connect(). No concrete production trigger or affected caller was identified beyond this conditional path. Before this change, connect() accessed *m_loop without synchronization in the same race, so this is an incomplete fix rather than a regression.

Treat a disengaged queue as finished in loopRef(); for example, throw the shutdown exception when the reference count is zero and either m_async_fns is disengaged or the queue is empty. The setup reference keeps the count nonzero, allowing the setup callback to acquire a reference.


Coverage details