getnamo / SocketIOClient-Unreal

Socket.IO client plugin for the Unreal Engine.
Other
897 stars 240 forks source link

5.1.0 Crash on Connect #358

Open edcolmar opened 1 year ago

edcolmar commented 1 year ago

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_ptr &) Line 741 C++ ExampleGameClient.exe!sio::client_impl<websocketpp::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 commented 1 year ago

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();
                    }
                }
getnamo commented 1 year ago

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.

edcolmar commented 1 year ago

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?

getnamo commented 1 year ago

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