Catching network disconnection

Is there a way to reduce the time it takes for the client to fail with network disconnection? or alternatively cancel the request?

I am trying to implement a way to overcome network disconnection. therefore I am recognizing when a request failed due to network issues and exposing a retry button. But it can take sometimes 60 seconds from the time I am disconnecting the network until the request is actually failed. (I can’t simply use a timer without canceling the requests, because if I will perform retry without canceling the request it might result in a duplicated requests)

@oshribin Is this for network requests sent from game clients with one of the client SDKs? Which one do you use?

Yes, I am using the unity sdk

@oshribin you can set the Timeout value on your Client object which defaults to fifteen seconds in the Unity SDK.

Since you’re noticing it taking longer than that I wonder if something else is at play. Are you wrapping your network calls in try..catch blocks to catch any network errors?

Yes I am actually wrapping the underlying client.RpcAsync with more than one try..catch blocks before the final error is being thrown but I don’t see why it will increase the time it takes to catch the error from 15 seconds to 60 seconds.

tnx

From what I can see SendAsync under Nakama.HttpRequestAdapter does not make any use of the timeout variable

@oshribin the UnityWebRequest adapter in the Unity client does make use of the timeout variable: https://github.com/heroiclabs/nakama-unity/blob/master/Packages/Nakama/Runtime/UnityWebRequestAdapter.cs#L109

Could you also share the error message you receive on network disconnection? Are you testing it using some network throttler or turning off the WIFI?

I will try the unityWebRequestAdapter.

I am testing both, I don’t get a disconnection with the throttler as it managed eventually to process the request. unless I am setting the throttler to 100% packet loss. then like with turning off the wifi. it takes about 60 seconds until I am getting the following excpetion:

nakama_call_failed: System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Network is unreachable) ---> System.Net.Sockets.SocketException: Network is unreachable at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in <735c83e43c004ee998f77c68cf8035da>:0 at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in <735c83e43c004ee998f77c68cf8035da>:0