@@ -69,7 +69,6 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
69
69
const auto & params = call_context.getParams ();
70
70
Context::Reader context_arg = Accessor::get (params);
71
71
ServerContext server_context{server, call_context, req};
72
- bool disconnected{false };
73
72
{
74
73
// Before invoking the function, store a reference to the
75
74
// callbackThread provided by the client in the
@@ -101,7 +100,7 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
101
100
// recursive call (IPC call calling back to the caller which
102
101
// makes another IPC call), so avoid modifying the map.
103
102
const bool erase_thread{inserted};
104
- KJ_DEFER ({
103
+ KJ_DEFER (if (erase_thread) {
105
104
std::unique_lock<std::mutex> lock (thread_context.waiter ->m_mutex );
106
105
// Call erase here with a Connection* argument instead
107
106
// of an iterator argument, because the `request_thread`
@@ -112,24 +111,10 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
112
111
// erases the thread from the map, and also because the
113
112
// ProxyServer<Thread> destructor calls
114
113
// request_threads.clear().
115
- if (erase_thread) {
116
- disconnected = !request_threads.erase (server.m_context .connection );
117
- } else {
118
- disconnected = !request_threads.count (server.m_context .connection );
119
- }
114
+ request_threads.erase (server.m_context .connection );
120
115
});
121
116
fn.invoke (server_context, args...);
122
117
}
123
- if (disconnected) {
124
- // If disconnected is true, the Connection object was
125
- // destroyed during the method call. Deal with this by
126
- // returning without ever fulfilling the promise, which will
127
- // cause the ProxyServer object to leak. This is not ideal,
128
- // but fixing the leak will require nontrivial code changes
129
- // because there is a lot of code assuming ProxyServer
130
- // objects are destroyed before Connection objects.
131
- return ;
132
- }
133
118
KJ_IF_MAYBE (exception, kj::runCatchingExceptions ([&]() {
134
119
server.m_context .loop ->sync ([&] {
135
120
auto fulfiller_dispose = kj::mv (fulfiller);
0 commit comments