NError: CancelledByUser

Inching toward a functional DEV environment here. I was able to get the C++ Client to compile. Next step is to authenticate with my test server.

I copied the code from the C++ Client guide and ran the Start method. The logger reports back NError: CancelledByUser.

It’s possible there’s a problem with my Nakama/Docker install. But if that were the case I would expect an “unable to reach server” error or something, not a “CancelledByUser.” The fact that I get the same error when Docker isn’t running is telling.

Can anyone advise why the authentication is getting “CancelledByUser.” I’m certainly not cancelling it myself.

Below is the code I’m running (straight from the C++ Client Guide) and a screenshot of the result.

#include <iostream>
#include "nakama-cpp/Nakama.h"



using namespace Nakama;
using namespace std;

class NakamaSessionManager
{
public:
    NakamaSessionManager()
    {
        NClientParameters parameters;

        _client = createDefaultClient(parameters);
    }

    void start(const string& deviceId)
    {
        // to do: read session token from your storage
        string sessionToken;

        if (!sessionToken.empty())
        {
            // Lets check if we can restore a cached session.
            auto session = restoreSession(sessionToken);

            if (!session->isExpired())
            {
                // Session was valid and is restored now.
                _session = session;
                return;
            }
        }

        auto successCallback = [this](NSessionPtr session)
        {
            _session = session;

            // to do: save session token in your storage
            std::cout << "session token: " << session->getAuthToken() << std::endl;
        };

        auto errorCallback = [](const NError& error)
        {
        };

        _client->authenticateDevice(deviceId, opt::nullopt, opt::nullopt, {}, successCallback, errorCallback);
    }

protected:
    NClientPtr _client;
    NSessionPtr _session;
};

int main()
{
    NLogger::initWithConsoleSink(NLogLevel::Debug);
    NakamaSessionManager MySession;
    MySession.start("MyDeviceID");
}

Hey @mehoo, I think there are two issues here:

(1) We expose a client.tick() method to give C++ users control over which thread their responses are processed on. It looks like you need to launch a separate thread that calls tick at some fixed interval.

(2) I think the reason you’re seeing this issue is your main method ends as soon as you make your first request. This causes the destructor of the RestClient to invoke and it cancels all outbound requests as you are effectively ending the application. It’s up to you how you want to resolve this – you could have your application wait for a response before terminating or simply run indefinitely.

1 Like