zaphoyd / websocketpp

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

segfault on rpi 3B+ asio standalone when calling start_accept #828

Open FrankvdStam opened 5 years ago

FrankvdStam commented 5 years ago

Full code here: https://github.com/FrankvdStam/Tempy

For reference, this project is supposed to be a temperature monitor. It sends my pc's temperature over to the pi, the pi draw's a graph with opengl.

Reproduction: you need xorg-dev to run the program (opengl stuff) bash gmake2_premake5.lua make run the binary in the bin directory

Init glfw and glad
libGL error: MESA-LOADER: failed to retrieve device information
MESA-LOADER: failed to retrieve device information
MESA-LOADER: failed to retrieve device information
Init glfw and glad end
Init websocket
Asio initialized
Message handler initialized
listen initialized
**Segmentation fault**

I traced it to the start_accept call in websocket's constructor:

websocket::websocket(received_callback callback)
{
    std::cout << "Init websocket" << std::endl; 
    try {
        m_server.init_asio();
        std::cout << "Asio initialized" << std::endl; 
        using websocketpp::lib::placeholders::_1;
        using websocketpp::lib::placeholders::_2;
        //m_server.set_message_handler(bind(&on_message, this, _1, _2));
        m_server.set_message_handler(*callback);
        std::cout << "Message handler initialized" << std::endl; 
        m_server.listen(9002);
        std::cout << "listen initialized" << std::endl; 
        m_server.start_accept();
        std::cout << "Start accept initialized" << std::endl; 
    }
    catch (std::exception e)
    {
        std::cout << "Failed to init websocket: " << e.what() << std::endl;
    }
    std::cout << "Init websocket end" << std::endl; 
}

I'm building on windows and on the pi, it runs without issue on windows. You can try windows by running vs2019_premake5.bat and opening in visual studio.

NOTE: I build premake5 from source. Runing these commands will run the binaries I made. You might want to build your own premake? Maybe the makefiles in the git repo are fine so you don't have to? Untrustworthy sources yadayada.

What am I doing wrong? I looked for issues but did not find anything which seemed relevant for me.

FrankvdStam commented 5 years ago

gdb gives me this:

Program received signal SIGSEGV, Segmentation fault.
0x0004027c in asio::detail::thread_info_base::allocate<asio::detail::thread_info_base::default_tag> (this_thread=0x1, size=92)
    at libraries/asio/include/asio/detail/thread_info_base.hpp:71
71      if (this_thread && this_thread->reusable_memory_[Purpose::mem_index])

I have no idea what this means :)

Maybe I should ask over at the asio repo?

FrankvdStam commented 5 years ago

Since it was in a thread file or threading related construction, I tried constructing the websocket in the main function instead of outside of it. That does actually work. Problem solved I guess! I'll leave this issue open so someone can decide if any action should be taken.

Edit: putting it on the heap also works, that way I can define the pointer outside main, use it in methods, only construct it in main. I'm probably making a common mistake here, I'm not that experienced in C++.