@@ -582,9 +582,6 @@ void serverDestroy(Server& server)
582
582
template <typename ProxyClient, typename GetRequest, typename ... FieldObjs>
583
583
void clientInvoke (ProxyClient& proxy_client, const GetRequest& get_request, FieldObjs&&... fields)
584
584
{
585
- if (!proxy_client.m_context .connection ) {
586
- throw std::logic_error (" clientInvoke call made after disconnect" );
587
- }
588
585
if (!g_thread_context.waiter ) {
589
586
assert (g_thread_context.thread_name .empty ());
590
587
g_thread_context.thread_name = ThreadName (proxy_client.m_context .loop ->m_exe_name );
@@ -606,7 +603,16 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
606
603
std::exception_ptr exception ;
607
604
std::string kj_exception;
608
605
bool done = false ;
606
+ const char * disconnected = nullptr ;
609
607
proxy_client.m_context .loop ->sync ([&]() {
608
+ if (!proxy_client.m_context .connection ) {
609
+ const std::unique_lock<std::mutex> lock (invoke_context.thread_context .waiter ->m_mutex );
610
+ done = true ;
611
+ disconnected = " IPC client method called after disconnect." ;
612
+ invoke_context.thread_context .waiter ->m_cv .notify_all ();
613
+ return ;
614
+ }
615
+
610
616
auto request = (proxy_client.m_client .*get_request)(nullptr );
611
617
using Request = CapRequestTraits<decltype (request)>;
612
618
using FieldList = typename ProxyClientMethodTraits<typename Request::Params>::Fields;
@@ -631,9 +637,13 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
631
637
invoke_context.thread_context .waiter ->m_cv .notify_all ();
632
638
},
633
639
[&](const ::kj::Exception& e) {
634
- kj_exception = kj::str (" kj::Exception: " , e).cStr ();
635
- proxy_client.m_context .loop ->logPlain ()
636
- << " {" << invoke_context.thread_context .thread_name << " } IPC client exception " << kj_exception;
640
+ if (e.getType () == ::kj::Exception::Type::DISCONNECTED) {
641
+ disconnected = " IPC client method call interrupted by disconnect." ;
642
+ } else {
643
+ kj_exception = kj::str (" kj::Exception: " , e).cStr ();
644
+ proxy_client.m_context .loop ->logPlain ()
645
+ << " {" << invoke_context.thread_context .thread_name << " } IPC client exception " << kj_exception;
646
+ }
637
647
const std::unique_lock<std::mutex> lock (invoke_context.thread_context .waiter ->m_mutex );
638
648
done = true ;
639
649
invoke_context.thread_context .waiter ->m_cv .notify_all ();
@@ -644,6 +654,7 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
644
654
invoke_context.thread_context .waiter ->wait (lock, [&done]() { return done; });
645
655
if (exception ) std::rethrow_exception (exception );
646
656
if (!kj_exception.empty ()) proxy_client.m_context .loop ->raise () << kj_exception;
657
+ if (disconnected) proxy_client.m_context .loop ->raise () << disconnected;
647
658
}
648
659
649
660
// ! Invoke callable `fn()` that may return void. If it does return void, replace
0 commit comments