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

All NakamaSocket methods fail with 'Request cancelled.' #182

Closed
Coxcopi opened this issue Jun 11, 2023 · 6 comments
Closed

All NakamaSocket methods fail with 'Request cancelled.' #182

Coxcopi opened this issue Jun 11, 2023 · 6 comments

Comments

@Coxcopi
Copy link
Contributor

Coxcopi commented Jun 11, 2023

I have the socket setup correctly, but all methods immediately return a NakamaException with error message "Request cancelled." that looks like this:
NakamaException(StatusCode={-1}, Message='{Request cancelled.}', GrpcStatusCode={-1}).
Any idea what might be going on here? (The server is also running and the client successfully connects to it, the only thing that's not working is the sockets).

Using Godot v4.0.2 stable and nakama-godot on the master branch.

@lugehorsam
Copy link
Contributor

Hey @Coxcopi could you share a snippet of your code and where the exception is raised?

@Coxcopi
Copy link
Contributor Author

Coxcopi commented Jun 11, 2023

@lugehorsam sure, this is what the code for setting up client and socket looks like:

func setup() -> void:
	_client = _connect_to_server()
	_socket = _create_socket(_client)

func _connect_to_server() -> NakamaClient:
	var client : NakamaClient = Nakama.create_client(
		"defaultkey",
		"127.0.0.1",
		7350,
		"http",
		3,
		NakamaLogger.LOG_LEVEL.INFO
	)
	client.timeout = CLIENT_REQUEST_TIMEOUT
	return client

func _create_socket(client : NakamaClient) -> NakamaSocket:
	if (!client):
		return null
	return Nakama.create_socket_from(client)

And here's when I tried using methods from the socket:

Joining Matchmaker:

func join_matchmaker(query : String = "*", min_count : int = 2, max_count : int = 8) -> void:
	var socket : NakamaSocket = NetServerConnection.get_socket()
	if (!socket):
		return
	var ticket_response : NakamaRTAPI.MatchmakerTicket = await socket.add_matchmaker_async(
		query, 
		min_count,
		max_count
	)
	if (ticket_response.is_exception()):
		Logger.log_error("NetMatchManager: join_matchmaker() error: %s" % ticket_response)
	matchmaker_ticket = ticket_response.ticket

Following friends status:

func follow_friends_status() -> void:
	var socket : NakamaSocket = NetServerConnection.get_socket()
	if (!socket):
		return
	var friends_result : Array[NakamaAPI.ApiUser] = await get_friends(FriendshipState.MUTUAL, 20)
	var friend_ids : Array[String] = []
	for user in friends_result:
		if (!user.online):
			continue
		friend_ids.append(user.id)
	var result : NakamaAsyncResult = await socket.follow_users_async(friend_ids, [])
	if (result.is_exception()):
		Logger.log_error("PresenceManager: follow_friends_status() error: %s" % result.get_exception().message)

Both of these resulted in the error I mentioned, and I can't seem to figure out where the problem is coming from.

@Coxcopi
Copy link
Contributor Author

Coxcopi commented Jun 11, 2023

Not sure if that information is also relevant but I'm running the latest nakama docker image locally on a Windows 10 machine using Docker Desktop.

@dsnopek
Copy link
Contributor

dsnopek commented Jun 13, 2023

The Request cancelled. cancelled message comes from the client when there's an error sending data on the WebSocket.

Is there any information in the Nakama logs? In particular, do you see the WebSocket connection coming through?

Also, your code doesn't show authenticating before creating the socket. I'm assuming you're doing that and simply not showing it, but double checking just in case. :-)

@Coxcopi
Copy link
Contributor Author

Coxcopi commented Jun 13, 2023

@dsnopek there actually is an error thrown in Godot (which I unfortunately didn't really notice before, otherwise I would've included it in the original issue of course), which seems to happen in the NakamaSocketAdapter.send() method:

E 0:00:12:0795   NakamaSocketAdapter.gd:54 @ send(): Condition "ready_state != STATE_OPEN" is true. Returning: FAILED

Looks like something's wrong with the WebSocket, though I'm not sure if it's an issue with the Nakama addon code or if I'm just missing something.

Also you're absolutely right, I left out the authentication code as I don't think it has to do with the problem, and I made sure that the authentication was working as intended.

Full stacktrace:

  <C++ Source>   modules/websocket/wsl_peer.cpp:703 @ _send()
  <Stack Trace>  NakamaSocketAdapter.gd:54 @ send()
                 NakamaSocket.gd:295 @ _send_async()
                 NakamaSocket.gd:351 @ follow_users_async()
                 net_account_manager.gd:237 @ follow_friends_status()
                 net_account_manager.gd:1347839312 @ get_friends()
                 NakamaClient.gd:1347838512 @ list_friends_async()
                 NakamaAPI.gd:1347838192 @ list_friends_async()
                 NakamaHTTPAdapter.gd:1347836752 @ send_async()
                 NakamaHTTPAdapter.gd:1347841872 @ _send_async()
                 NakamaHTTPAdapter.gd:1347842832 @ make_request()

@Coxcopi
Copy link
Contributor Author

Coxcopi commented Jul 31, 2023

It turns out I'm incredibly stupid. I spent hours digging through the addon code trying to find errors when I just now realized that I never actually called _socket.connect(), which of course has my methods fail simply because the socket obviously can't send anything without a connection.
I apologize for keeping this issue open for so long (and making it in the first place), next time I'll check my own code first 😄

@Coxcopi Coxcopi closed this as completed Jul 31, 2023
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