Error callback in Realtime Client called several times

I found strange behaviour of the Listener from UNakamaRealtimeClient.
We use the same code for setup and connection of Realtime Client as here: Heroic Labs Documentation | Unreal

But, the OnRealtimeClientConnectionError() is called several times and our program crashes.

I found that the Realtime Client register the error callback here:

void UNakamaRealtimeClient::Connect(const FOnRealtimeClientConnected& Success, const FOnRealtimeClientError& Error)
{
	const NRtClientProtocol SelectedProtocol = static_cast<NRtClientProtocol>(Protocol);

...

	Listener.setErrorCallback([this, Error](const NRtError& Err)
	{
		UE_LOG(LogTemp, Warning, TEXT("Nakama Realtime Client Setup: Socket Connect Error"));
		Error.Broadcast();
	});

From my point of view, it’s a very unspecific callback for the Listener. Because a different function from Nakama SDK calls OnError, and then our error delegate function is called.

void ASagiShiActor::OnRealtimeClientConnectionError()
{
    UE_LOG(LogTemp, Log, TEXT("Socket connection failed."));
}

There is my callstack:

UnrealEditor-NakamaUnreal-Win64-DebugGame.dll!Nakama::NRtDefaultClientListener::onError() [Nakama\Source\NakamaCore\Public\nakama-cpp\realtime\NRtDefaultClientListener.h:76]
nakama-sdk.dll!UnknownFunction
nakama-sdk.dll!UnknownFunction
UnrealEditor-NakamaCore-Win64-DebugGame.dll!std::_Func_class<void,std::basic_string<char,std::char_traits,std::allocator > const &>::operator()() [C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\INCLUDE\functional:862]
UnrealEditor-NakamaCore-Win64-DebugGame.dll!Nakama::NRtTransportInterface::fireOnMessage() [Nakama\Source\NakamaCore\Public\nakama-cpp\realtime\NRtTransportInterface.h:115]
UnrealEditor-NakamaCore-Win64-DebugGame.dll!Nakama::Unreal::UnrealWsTransport::tick() [Nakama\Source\NakamaCore\Private\websocket.cpp:120]
UnrealEditor-NakamaUnreal-Win64-DebugGame.dll!UNakamaRealtimeClient::Tick() [Nakama\Source\NakamaUnreal\Private\NakamaRealtimeClient.cpp:36]
UnrealEditor-Engine.dll!FTickableGameObject::TickObjects() [\Engine\Private\Tickable.cpp:153]

{Solution}
I suggest changing the error callback for UNakamaRealtimeClient::Connect(…). For example for

Listener.setConnectErrorCallback(....)

and don’t use the global error callback.

{Details}
Versions: Nakama {2.8.1}, {Windows}

Thanks for the report @j4c0b.
Would you mind creating an issue or pull request in our repo?

ok, @ftkg ,
I didn’t know how big problem it is. I created a new issue with a similar description: Error callback in Realtime Client called several times · Issue #100 · heroiclabs/nakama-unreal · GitHub

Thanks