Skip to content

Commit e84e0e2

Browse files
committed
Removing unnecessary event in winrt websocket client.
1 parent 9fcc601 commit e84e0e2

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

Release/src/websockets/client/ws_client_winrt.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,22 @@ class winrt_callback_client : public websocket_client_callback_impl, public std:
134134
{
135135
m_external_close_handler(status, reason, error_code);
136136
}
137+
138+
// Locally copy the task completion event since there is a PPL bug
139+
// that the set method accesses internal state in the event and the websocket
140+
// client could be destroyed.
141+
auto local_close_tce = m_close_tce;
137142
m_close_tce.set();
138-
m_server_close_complete.set();
139143
});
140144
}
141145

142146
~winrt_callback_client()
143147
{
144-
// task_completion_event::set() returns false if it has already been set.
145-
// In that case, wait on the m_server_close_complete event for the tce::set() to complete.
146-
// The websocket client on close handler (upon receiving close frame from server) will
147-
// set this event.
148-
// If we have not received a close frame from the server, this set will be a no-op as the
149-
// websocket_client is anyways destructing.
150-
if (!m_close_tce.set())
151-
{
152-
m_server_close_complete.wait();
153-
}
148+
// Locally copy the task completion event since there is a PPL bug
149+
// that the set method accesses internal state in the event and the websocket
150+
// client could be destroyed.
151+
auto local_close_tce = m_close_tce;
152+
m_close_tce.set();
154153
}
155154

156155
pplx::task<void> connect()
@@ -161,6 +160,8 @@ class winrt_callback_client : public websocket_client_callback_impl, public std:
161160
return pplx::task_from_exception<void>(websocket_exception("Only a default proxy server is supported."));
162161
}
163162

163+
164+
164165
const auto &proxy_cred = proxy.credentials();
165166
if(proxy_cred.is_set())
166167
{
@@ -409,12 +410,6 @@ class winrt_callback_client : public websocket_client_callback_impl, public std:
409410
ReceiveContext ^ m_context;
410411

411412
pplx::task_completion_event<void> m_close_tce;
412-
// There is a bug in ppl task_completion_event. The task_completion_event::set() accesses some
413-
// internal data after signaling the event. The waiting thread might go ahead and start destroying the
414-
// websocket_client. Due to this race, set() can cause a crash.
415-
// To workaround this bug, maintain another event: m_server_close_complete. We will signal this when the m_close_tce.set() has
416-
// completed. The websocket_client destructor can wait on this event before proceeding.
417-
Concurrency::event m_server_close_complete;
418413

419414
// External callback for handling received and close event
420415
std::function<void(websocket_incoming_message)> m_external_message_handler;

0 commit comments

Comments
 (0)