Skip to content

CRITICAL BLOCKER BUG: crash on websocket_client::run() #2409

@GTruf

Description

@GTruf

@stephenberry, hello! I am using MinGW with GCC 15.2.0, OpenSSL 3.6.0, glaze 7.2.2, and asio-1-38-0.
Occasionally, the websocket_client crashes upon startup. Through empirical testing and logging, I have identified the location where this occurs. It’s in the asio library file asio-src/include/asio/detail/impl/win_iocp_io_context.ipp, in the function win_iocp_io_context::do_one, at the line op->complete(this, result_ec, bytes_transferred);

I don’t understand what the problem might be there. I used GPT and Claude Sonnet to find the error and patched the code based on their advice, but nothing helped, so I hope you can find it faster. I’m attaching my code and the output (you can run the code right away; try it yourself):

#include "glaze/net/websocket_client.hpp"

int main() {
    glz::websocket_client client;

    client.set_ssl_verify_mode(asio::ssl::verify_none);

    // Setup event handlers
    client.on_open([]() {
        std::cout << "Connected to WebSocket server!" << std::endl;;
    });

    client.on_message([](std::string_view message, glz::ws_opcode opcode) {

    });

    client.on_close([](glz::ws_close_code code, std::string_view reason) {
        std::cout << "Connection closed with code: " << static_cast<int>(code);
        if (!reason.empty()) {
            std::cout << ", reason: " << reason;
        }
        std::cout << std::endl;
    });

    client.on_error([](std::error_code ec) {
        std::cerr << "Error: " << ec.message() << std::endl;
    });

    std::cout << "Try to connect" << std::endl;
    client.connect("wss://wseea.okx.com:8443/ws/v5/public");

    std::cout << "Try to run" << std::endl;
    client.run();
    std::cout << "After run" << std::endl;

    return 0;
}

asio code in win_iocp_io_context::do_one:

...
if (::InterlockedCompareExchange(&op->ready_, 1, 0) == 1)
{
  // Ensure the count of outstanding work is decremented on block exit.
  work_finished_on_block_exit on_exit = { this };
  (void)on_exit;
          
  std::cout << "Try to op->complete: " << __PRETTY_FUNCTION__ << std::endl; // <--- my log
  op->complete(this, result_ec, bytes_transferred);
  std::cout << "Ok completed: " << __PRETTY_FUNCTION__ << std::endl; // <--- my log
  this_thread.rethrow_pending_exception();
  ec = asio::error_code();
  return 1;
}
...

Output:

Try to connect
Try to run
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)
Ok completed: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::error_c
ode&)
Try to op->complete: size_t asio::detail::win_iocp_io_context::do_one(DWORD, asio::detail::win_iocp_thread_info&, asio::
error_code&)

Process finished with exit code -1073741819 (0xC0000005)

This appears to be a serious, critical blocking bug at first glance; please take a look at it as soon as possible. Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions