zaphoyd / websocketpp

C++ websocket client/server library
http://www.zaphoyd.com/websocketpp
Other
6.9k stars 1.95k forks source link

Runs fine on Linux, crash on Windows due to boost invalid memory access issue #1134

Open sierret opened 3 months ago

sierret commented 3 months ago

For context, I'm using this in a multi-threaded environment. I run main in an infinite loop and .detach() threads and while also having a single .join() running as the main. I have some global variables accessed by the websocket as well if that matters. My application runs great on Linux but on Windows I receive the error:

terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>' what(): Invalid access to memory location [system:998]

It is quite strange. I also built the app using MingW(& websocketpp built using vcpkg x64-mingw-static triplet) which can be quite hit or miss sometimes requiring a lot of programmer intervention and research to get stuff compiled and linked. After successful compilation, I imagined that would be the end of MingW headache, but I don't know if it's related to that.

As this seems boost related, I wanted to try to use asio standalone. I did use the headers [ASIO_STANDALONE & _WEBSOCKETPP_CPP11_TYPETRAITS] but this gives issues with my code which was built for boost. If possible, I guess as a plan B, I'd need to convert this on_tls_init code below to work with asio standalone(which I have no idea how to do):

`context_ptr myfunc::on_tls_init(websocketpp::connection_hdl) { m_tls_init = std::chrono::high_resolution_clock::now(); context_ptr ctx = websocketpp::lib::make_shared(boost::asio::ssl::context::tlsv12);

    try {
        ctx->set_options(boost::asio::ssl::context::default_workarounds |
                         boost::asio::ssl::context::no_sslv2 |
                         boost::asio::ssl::context::no_sslv3 |
                         boost::asio::ssl::context::single_dh_use);
        ctx->set_verify_mode(boost::asio::ssl::verify_none);
    } catch (std::exception& e) {
        std::cout << e.what() << std::endl;
    }
    return ctx;
}`

As well as the context_ptr def :

typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;

Please direct me to example code if already exists. Or general direction. Any help appreciated.

sierret commented 3 months ago

Issue seems Mingw related.

I compiled on MSVC and works fine.

sierret commented 3 months ago

Decided to re-open issue in case of further update. But as of currently, if any one runs into similar issue please compile using MSVC( thus and Visual Studio on Windows, eww) on or GCC with Linux. MingW on either Linux or Windows seems problematic.