Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions on createDefaultClient and rtClient->tick() #160

Open
rumichi2210 opened this issue Jul 19, 2024 · 4 comments
Open

Exceptions on createDefaultClient and rtClient->tick() #160

rumichi2210 opened this issue Jul 19, 2024 · 4 comments

Comments

@rumichi2210
Copy link

Nakama Server version 3.22.0+4a4c53d7

nakama cpp version: [v2.8.5]

When I run nakama-cpp/example/main.cpp in a windows environment

different parts crash in both releasebuild and debugbuild.

In releasebuild

auto client = Nakama::createDefaultClient(params);

an exception is raised at runtime, and

In debug build

rtClient->tick() crashes on the third call.

Similar issues encountered in the past

C++ SDK crashes on createDefaultClient - Heroic Labs

I tried v2.7.0 and the situation did not change.

Log in debug build: --------------------------------------------------------

[Nakama::RestClient::RestClient] Created: NakamaSdkVersion: 2.8.5 git:27322aa
[Nakama::RestClient::authenticateDevice] ...
'nakama-cpp-sample.exe' (Win32): 'C:\WindowsSystem32\mswsock.dll' loaded. Symbol loading is disabled in the Include/Exclude setting.
[tick] invoking curl callback
[NRtClient::NRtClient] Created
[NRtClient::connect] ...
[tick] curl_multi_remove_handle() failed, code 2.

[tick] Wslay state: Connecting
[tick] Wslay state: Connecting
'nakama-cpp-sample.exe' (Win32): 'C:\WindowsSystem32\cryptbase.dll' was loaded. Symbol loading is disabled in the Include/Exclude setting.
'nakama-cpp-sample.exe' (Win32): 'C:\Windows\System32\bcryptprimitives.dll' was loaded. Symbol loading is disabled in the Include/Exclude setting.
[tick] Wslay state: Handshake sending
[tick] Wslay state: Handshake receiving
[tick] Wslay state: Handshake receiving
Exception thrown in 0x00007FF8972BB7C4 (in nakama-sdk.dll): 0xC0000005: An access violation occurred while reading location 0xFFFFFFFFFFFFFFFFFFFFFF.

Server side log: -----------------------------------------------------------------------------

`nakama | {"level": "debug", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/session_ws.go:205", "msg": "Error reading message from client` `", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46", "error": "websocket: close 1006 (abnormal` `closure): unexpected EOF"}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/session_ws.go:442", "msg": "Cleaning up closed client connection` `", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46"}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/session_ws.` `go:450", "msg": "Cleaned up closed connection matchmaker", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46"}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/session_ws.` `go:454", "msg": "Cleaned up closed connection tracker", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46"}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/session_ws.` `go:458", "msg": "Cleaned up closed connection status registry", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46"}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/session_ws.` `go:462", "msg": "Cleaned up closed connection session registry", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46"}`
`nakama | {"level": "debug", "ts": "2024-07-11T09:55:50.211Z", "caller": "server/tracker.go:912", "msg": "Processing presence event", "joins":0, "leaves":1}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.212Z", "caller": "server/session_ws.go:520", "msg": "Closed client connection", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "bbc3b5bd-3f6b-11ef-b440-7106fdcb5b46"}`
`nakama | {"level": "info", "ts": "2024-07-11T09:55:50.699Z", "caller": "server/session_ws.` `go:81", "msg": "New WebSocket session connected", "uid": "b33d655e-1087-4868-bf66-609d99098cd1", "sid": "c13047b3-3f6b-11ef-b440-7106fdcb5b46", "format":0}`
`nakama | {"level": "debug", "ts": "2024-07-11T09:55:50.699Z", "caller": "server/tracker.go:912", "msg": "Processing presence event", "joins":1, "leaves":0}`
Copy link

linear bot commented Jul 19, 2024

@rumichi2210 rumichi2210 changed the title C++ SDK exceptions on createDefaultClient and rtClient->tick() exceptions on createDefaultClient and rtClient->tick() Jul 19, 2024
@rumichi2210 rumichi2210 changed the title exceptions on createDefaultClient and rtClient->tick() Exceptions on createDefaultClient and rtClient->tick() Jul 19, 2024
@redbaron
Copy link
Contributor

redbaron commented Jul 22, 2024

Could you provide a minimal reproducer of the problem for us to look at? Is it unmodified example/main.cpp from this repo?

@rumichi2210
Copy link
Author

I only changed the ipAddress in example/main.cpp.

#include <nakama-cpp/Nakama.h>
#include "nakama-cpp/realtime/NRtDefaultClientListener.h"
#include <iostream>
#include <chrono>
#include <thread>
#include <optional>

int mainHelper();

int main() {
    return mainHelper();
}

int mainHelper() {
    Nakama::NLogger::initWithConsoleSink(Nakama::NLogLevel::Debug);
    Nakama::NClientParameters params;
    params.serverKey = "defaultkey";
    params.host = "192.168.200.100";
    params.port = Nakama::DEFAULT_PORT;
    auto client = Nakama::createDefaultClient(params);
    Nakama::NRtClientPtr rtClient = nullptr;
    bool done = false;
    auto loginFailedCallback = [&done](const Nakama::NError &error) {
        NLOG_INFO("Failed to login");
        NLOG_INFO(error.message);
        done = true;
    };

    auto connectSucceededCallback = [&done]() {
        NLOG_INFO("Done connecting socket");
        done = true;
    };

    auto rtErrorCallback = [&done](const Nakama::NRtError& error) {
        NLOG_INFO("Error from socket:...");
        NLOG_INFO(error.message);
        done = true;
    };

    auto loginSucceededCallback = [&done, &connectSucceededCallback, &rtErrorCallback, &client, &rtClient](Nakama::NSessionPtr session) {
        NLOG_INFO("Login successful");
        NLOG_INFO(session->getAuthToken()); // raw JWT token
        Nakama::NRtDefaultClientListener listener;
        listener.setConnectCallback(connectSucceededCallback);
        listener.setErrorCallback(rtErrorCallback);
        rtClient = client->createRtClient();
        rtClient->setListener(&listener);
        NLOG_INFO("Connecting socket");
        rtClient->connect(session, true, Nakama::NRtClientProtocol::Json);
    };

    std::string deviceId = "e872f976-34c1-4c41-88fe-fd6aef118782";
    NLOG_INFO("Authenticating...");

    client->authenticateDevice(
            deviceId,
            Nakama::opt::nullopt,
            Nakama::opt::nullopt,
            {},
            loginSucceededCallback,
            loginFailedCallback);

    while (!done) {
        client->tick();

        if (rtClient)
        {
            rtClient->tick();
        }

        std::this_thread::sleep_for(std::chrono::milliseconds(50));
    }

    NLOG_INFO("Press any key to continue");
    getchar();
    client->disconnect();
    return 0;
}

@benessbbyy
Copy link

benessbbyy commented Aug 29, 2024

I am experiencing the same issue.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants