Skip to content

Fix thread not joined #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions Release/src/websockets/client/ws_client_wspp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,23 +400,26 @@ class wspp_callback_client : public websocket_client_callback_impl,

m_state = CONNECTING;
client.connect(con);
m_thread = std::thread([&client]() {
{
std::lock_guard<std::mutex> lock(m_wspp_client_lock);
m_thread = std::thread([&client]() {
#if defined(__ANDROID__)
crossplat::get_jvm_env();
crossplat::get_jvm_env();
#endif
client.run();
client.run();
#if defined(__ANDROID__)
crossplat::JVM.load()->DetachCurrentThread();
crossplat::JVM.load()->DetachCurrentThread();
#endif

#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
// OpenSSL stores some per thread state that never will be cleaned up until
// the dll is unloaded. If static linking, like we do, the state isn't cleaned up
// at all and will be reported as leaks.
// See http://www.openssl.org/support/faq.html#PROG13
ERR_remove_thread_state(nullptr);
// OpenSSL stores some per thread state that never will be cleaned up until
// the dll is unloaded. If static linking, like we do, the state isn't cleaned up
// at all and will be reported as leaks.
// See http://www.openssl.org/support/faq.html#PROG13
ERR_remove_thread_state(nullptr);
#endif
});
});
} // unlock
return pplx::create_task(m_connect_tce);
}

Expand Down Expand Up @@ -648,10 +651,13 @@ class wspp_callback_client : public websocket_client_callback_impl,

// Can't join thread directly since it is the current thread.
pplx::create_task([this, connecting, ec, closeCode, reason] {
if (m_thread.joinable())
{
m_thread.join();
}
std::lock_guard<std::mutex> lock(m_wspp_client_lock);
if (m_thread.joinable())
{
m_thread.join();
}
} // unlock

// Delete client to make sure Websocketpp cleans up all Boost.Asio portions.
m_client.reset();
Expand Down