InitCrypto Intermittently Fails

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

evfaca
Posts: 6
Joined: 09 Apr 2020, 14:19

InitCrypto Intermittently Fails

Postby evfaca » 09 Apr 2020, 14:27

I've been using SFS2X for a couple months in development, and while testing we weren't using SSL. Now that we are starting to get ready for deployment we set up SSL certs for the server and related websites. Initially after installing the cert to the SFS2X installation InitCrypto connections appeared to be fine, albeit taking about 3x as long as a normal login request, however now the server appears to fail all encryption requests randomly before processing requests properly again. Is this standard behavior for a SFS2X deployment, or are there some settings I need to tweak? The returned error is not particularly descriptive -> Encryption initialization failed: An error occurred while sending the request -> so I'm uncertain if its simply timing out or if there is something else going on.
User avatar
Lapo
Site Admin
Posts: 21522
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: InitCrypto Intermittently Fails

Postby Lapo » 09 Apr 2020, 15:08

Hi,
we need more info to understand what might be going on.
- What version of SFS2X is being used
- client technology and client API version does the client use
- which side of the communication fails? Is it client or server side? Do you have specific error logs (with stack traces) related to these failures?

Have you found a way to reproduce the issue?
Does it happen at specific times (i.e. peak hours)?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
evfaca
Posts: 6
Joined: 09 Apr 2020, 14:19

Re: InitCrypto Intermittently Fails

Postby evfaca » 09 Apr 2020, 15:59

Using SFS2X 2.14.0
Client side is C# using Unity, the client side is the side that fails. I'm not certain where to find the client API version, there isn't anything in the readme files in the package downloaded from the SFS website, however the client side files were downloaded in Jan 2020.
Client side will fail seemingly at random with the following stack trace, the server does not print any trace :
[SFS > ERROR] Encryption initialization failed: An error occurred while sending the request
UnityEngine.Debug:Log(Object)
ACA.iD.Collaborate.SFSLoginUtility:ShowLogMessage(String, String) (at Assets/iDCollaborate/Scripts/Connection/SFSLoginUtility.cs:217)
ACA.iD.Collaborate.SFSLoginUtility:OnCryptoInit(BaseEvent) (at Assets/iDCollaborate/Scripts/Connection/SFSLoginUtility.cs:158)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
ACA.iD.Collaborate.SmartFoxConnection:Update() (at Assets/iDCollaborate/Scripts/Connection/SmartFoxConnection.cs:29)

I tested the SSL certificate with an ssl checker (https://www.sslshopper.com/ssl-checker.html) recommended in another post related to InitCrypto issues, and it returns that the SSL cert is valid.

EDIT: I will note that regardless of whether the encryption succeeds or fails it takes a significantly longer time to return from the server than login without encryption, about 15 seconds longer.

Also I just updated the client API to 1.7.13 and the problem persists
User avatar
Lapo
Site Admin
Posts: 21522
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: InitCrypto Intermittently Fails

Postby Lapo » 10 Apr 2020, 09:33

Hi,
are you sure it's taking 15 seconds for the initCrypto to complete? I ask because 15 seconds is way too much and it should probably cause a timeout error.
We have tested an SSL connection in Unity from our connection in Italy to a server in the U.S. (so not exactly around the corner) and it takes around 1.5 seconds to connect + init TLS + login into a Zone. The initCrypto alone takes ~970ms.

Have you tried testing from both the Unity Editor and the built executable to see if there's any difference?
Are your client tests done from the same network or did you try different ones?

Where are the server and client locate? (country / state)

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 21522
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: InitCrypto Intermittently Fails

Postby Lapo » 10 Apr 2020, 09:36

One more thing. What happens if you just point your browser to https://your-server-domain:8443 ?
In theory you should see the SFS2X welcome page appear instantly.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Bax
Site Admin
Posts: 4515
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: InitCrypto Intermittently Fails

Postby Bax » 10 Apr 2020, 10:19

When the CRYPTO_INIT event is fired, you have access to two parameters: "success" and "errorMsg".
What error message are you getting?
Paolo Bax
The SmartFoxServer Team
evfaca
Posts: 6
Joined: 09 Apr 2020, 14:19

Re: InitCrypto Intermittently Fails

Postby evfaca » 10 Apr 2020, 14:14

@Lapo - I've double checked the full login pipeline, it looks like another engineer stuck a long awaitable in the callback chain, relocating that awaitable reduced the crypto callback to be the same 1s as the normal login call, sorry about that. The build version and the editor version have the same issues and have been tested on 7 different networks. The server is located in Oregon, USA, the test connections are being made from Kansas, USA.

Additionally going to https://mydomain.com:8443 does show the welcome page with the secure lock to indicate the SSL was successful and loads reasonably quickly.

@Bax - The error message I posted above is the errorMessage "An error occurred while sending the request", trying to echo out evt.Params["errorMsg"] returns a key not found exception
This is my CRYPTO_INIT event reciever :

Code: Select all

       
        private void OnCryptoInit(BaseEvent evt)
        {
            if ((bool)evt.Params["success"])
            {
                ShowLogMessage("INFO", "Encryption initialized successfully");

                // Attempt login
                login();
            }
            else
            {
                //onFailure?.Invoke("Encryption initialization failed: " + (string)evt.Params["errorMessage"]);
                ShowLogMessage("ERROR", "Encryption initialization failed: " + (string)evt.Params["errorMessage"]);
            }
        }
Last edited by evfaca on 10 Apr 2020, 14:31, edited 1 time in total.
User avatar
Bax
Site Admin
Posts: 4515
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: InitCrypto Intermittently Fails

Postby Bax » 10 Apr 2020, 14:31

evfaca wrote:@Bax - The error message I posted above is the errorMessage, trying to echo out evt.Params["errorMsg"] returns a key not found exception


Pay attentions to the key: it's errorMsg, not errorMessage.
Paolo Bax
The SmartFoxServer Team
evfaca
Posts: 6
Joined: 09 Apr 2020, 14:19

Re: InitCrypto Intermittently Fails

Postby evfaca » 10 Apr 2020, 14:32

@Bax - I printed every key I get from evt

success : False
errorMessage : An error occurred while sending the request

There isn't an errorMsg being returned

Debug Code:

Code: Select all

           
            foreach (KeyValuePair<string, object> par in evt.Params)
            {
                Debug.Log("Param : " + par.Key + " : " + par.Value);
            }


EDIT : I've double checked the C# API documentation, http://docs2x.smartfoxserver.com/api-do ... 9100fd.htm and http://docs2x.smartfoxserver.com/Exampl ... -connector both show the returned error key as errorMessage.
User avatar
Bax
Site Admin
Posts: 4515
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: InitCrypto Intermittently Fails

Postby Bax » 11 Apr 2020, 10:16

You are right, sorry, my fault. The parameter is "errorMessage".
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
Posts: 4515
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: InitCrypto Intermittently Fails

Postby Bax » 11 Apr 2020, 10:32

That useful error message ("An error occurred while sending the request") is returned by the exception raised when the connection to initialize encryption is attempted by this code inside the API:

Code: Select all

 try
{
    var req = await httpClient.PostAsync ("", formContent);
    req.EnsureSuccessStatusCode();

    string res = req.Content.ReadAsStringAsync().Result;

    OnHttpResponse (res);
}

catch (Exception ex)
{
   OnHttpError (ex.Message);
}


So everything relies on System.Net.Http.HttpClient. We are still not sure why you get that random behavior.
Paolo Bax
The SmartFoxServer Team
User avatar
Lapo
Site Admin
Posts: 21522
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: InitCrypto Intermittently Fails

Postby Lapo » 11 Apr 2020, 10:41

@evfaca:
Can you send us the IP address of the server? So we can run a few connection tests from remote?
Also send us a valid zone and credentials for the login.
You can use a forum private message, or get in touch via our support@... email box. (if you use the latter please add a reference to this discussion)

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
evfaca
Posts: 6
Joined: 09 Apr 2020, 14:19

Re: InitCrypto Intermittently Fails

Postby evfaca » 12 Apr 2020, 16:36

Send you a PM @Lapo
evfaca
Posts: 6
Joined: 09 Apr 2020, 14:19

Re: InitCrypto Intermittently Fails

Postby evfaca » 16 Apr 2020, 16:11

After coordinating with Lapo via PM, this problem has been solved. Ultimately the issue was I was using the IP of the server to connect rather than the hostname.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 1 guest