@@ -592,9 +592,6 @@ void serverDestroy(Server& server)
592
592
template <typename ProxyClient, typename GetRequest, typename ... FieldObjs>
593
593
void clientInvoke (ProxyClient& proxy_client, const GetRequest& get_request, FieldObjs&&... fields)
594
594
{
595
- if (!proxy_client.m_context .connection ) {
596
- throw std::logic_error (" clientInvoke call made after disconnect" );
597
- }
598
595
if (!g_thread_context.waiter ) {
599
596
assert (g_thread_context.thread_name .empty ());
600
597
g_thread_context.thread_name = ThreadName (proxy_client.m_context .loop ->m_exe_name );
@@ -616,7 +613,16 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
616
613
std::exception_ptr exception;
617
614
std::string kj_exception;
618
615
bool done = false ;
616
+ const char * disconnected = nullptr ;
619
617
proxy_client.m_context .loop ->sync ([&]() {
618
+ if (!proxy_client.m_context .connection ) {
619
+ const std::unique_lock<std::mutex> lock (invoke_context.thread_context .waiter ->m_mutex );
620
+ done = true ;
621
+ disconnected = " IPC client method called after disconnect." ;
622
+ invoke_context.thread_context .waiter ->m_cv .notify_all ();
623
+ return ;
624
+ }
625
+
620
626
auto request = (proxy_client.m_client .*get_request)(nullptr );
621
627
using Request = CapRequestTraits<decltype (request)>;
622
628
using FieldList = typename ProxyClientMethodTraits<typename Request::Params>::Fields;
@@ -641,9 +647,13 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
641
647
invoke_context.thread_context .waiter ->m_cv .notify_all ();
642
648
},
643
649
[&](const ::kj::Exception& e) {
644
- kj_exception = kj::str (" kj::Exception: " , e).cStr ();
645
- proxy_client.m_context .loop ->logPlain ()
646
- << " {" << invoke_context.thread_context .thread_name << " } IPC client exception " << kj_exception;
650
+ if (e.getType () == ::kj::Exception::Type::DISCONNECTED) {
651
+ disconnected = " IPC client method call interrupted by disconnect." ;
652
+ } else {
653
+ kj_exception = kj::str (" kj::Exception: " , e).cStr ();
654
+ proxy_client.m_context .loop ->logPlain ()
655
+ << " {" << invoke_context.thread_context .thread_name << " } IPC client exception " << kj_exception;
656
+ }
647
657
const std::unique_lock<std::mutex> lock (invoke_context.thread_context .waiter ->m_mutex );
648
658
done = true ;
649
659
invoke_context.thread_context .waiter ->m_cv .notify_all ();
@@ -654,6 +664,7 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
654
664
invoke_context.thread_context .waiter ->wait (lock, [&done]() { return done; });
655
665
if (exception) std::rethrow_exception (exception);
656
666
if (!kj_exception.empty ()) proxy_client.m_context .loop ->raise () << kj_exception;
667
+ if (disconnected) proxy_client.m_context .loop ->raise () << disconnected;
657
668
}
658
669
659
670
// ! Invoke callable `fn()` that may return void. If it does return void, replace
0 commit comments