Fix a race condition reported in #348 where if a disconnect happens during an IPC call that uses a worker thread (an IPC call taking an mp.Context parameter), it can trigger a read-write race detected by TSAN, and also theoretically cause a null pointer dereference (described in the commit message).
The race condition happens because when RpcCallContext::getResults() is called for the first time, it checks the connection state. So currently if there is a disconnect, when the worker thread calls getResults, this can read connection state at the same time capnproto writes as it processes the disconnect.
Fix this issue by calling getResults once from the event loop thread before executing the IPC call on the worker thread, so the results message pointer will be cached, and future calls to getResults from the worker thread won't access the connection state or have any race condition.
This is a one-line fix with many comments and a test.