SocketIOClient-Unreal icon indicating copy to clipboard operation
SocketIOClient-Unreal copied to clipboard

5.1.0 Crash on Connect

Open edcolmar opened this issue 3 years ago • 4 comments

I'm updating my code to 5.1.0 and I'm getting a crash on connect. I'm using NativeClient within c++

Win10 development client build, VS 2022

Exception thrown: read access violation. obj_ptr was nullptr.

Top of the call stack:

ExampleGameClient.exe!sio::socket::impl::on_message_packet(const sio::packet & p) Line 407 C++ [Inline Frame] ExampleGameClient.exe!sio::socket::on_message_packet(const sio::packet &) Line 639 C++ [Inline Frame] ExampleGameClient.exe!sio::client_impl_base::socket_on_message_packet(std::shared_ptrsio::socket &) Line 741 C++ ExampleGameClient.exe!sio::client_impl<websocketpp::clientwebsocketpp::config::asio_client>::on_decode(const sio::packet & p) Line 627 C++ [Inline Frame] ExampleGameClient.exe!std::_Func_class<void,sio::packet const &>::operator()(const sio::packet &) Line 968 C++ ExampleGameClient.exe!sio::packet_manager::put_payload(const std::string & payload) Line 529 C++

My Code:

FSIOConnectParams Params; Params.AddressAndPort = InAddressAndPort; //Params.Path = InPath; //Params.AuthToken = InAuthToken; Params.Query = USIOMessageConvert::JsonObjectToFStringMap(Query); Params.Headers = USIOMessageConvert::JsonObjectToFStringMap(Headers); NativeClient->Connect(Params);

Also maybe related?

NativeClient->OnConnectedCallback = [this](const FString& InSocketId, const FString& InSessionId ) { FCULambdaRunnable::RunShortLambdaOnGameThread([this, InSocketId, InSessionId] { if (this) { bIsConnected = true; SessionId = InSessionId; SocketId = InSocketId; bIsHavingConnectionProblems = false; } }); };

edcolmar avatar Nov 27 '22 22:11 edcolmar

I worked around this by adding a check for obj_ptr. It avoids the crash, and seems to be working. I'm not sure what effect this might have to the rest of the codebase.

sio_socket.cpp line 407:

               const object_message* obj_ptr = static_cast<const object_message*>(p.get_message().get());
                if (obj_ptr)
                {
                    const map<string, message::ptr>* values = &(obj_ptr->get_map());
                    auto it = values->find("sid");
                    if (it != values->end()) {
                        m_socket_id = static_pointer_cast<string_message>(it->second)->get_string();
                    }
                }

edcolmar avatar Jan 15 '23 22:01 edcolmar

Likely needs more context (e.g. socket.io host type) because it appears the packet you receive on connection has an empty object returned, which isn't standard socket.io server spec IIRC. The if barrier is valid workaround, but it does mean m_socket_id might not be filled in your connection setup, which means if you access socketid later on it will likely be invalid.

getnamo avatar Jan 18 '23 09:01 getnamo

Likely needs more context (e.g. socket.io host type) because it appears the packet you receive on connection has an empty object returned, which isn't standard socket.io server spec IIRC. The if barrier is valid workaround, but it does mean m_socket_id might not be filled in your connection setup, which means if you access socketid later on it will likely be invalid.

Thanks for the response. Is this due to incorrect setup client side? Or a server running an old/incompatible version?

edcolmar avatar Jan 19 '23 18:01 edcolmar

Suspecting a non standard server, e.g. a incomplete spec python server maybe? Check that it support socket.io protocol v3+

getnamo avatar Jan 19 '23 19:01 getnamo