pingpongrequest

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Mrm83
Posts: 155
Joined: 17 Dec 2017, 04:02

pingpongrequest

Postby Mrm83 » 24 Nov 2022, 13:58

Getting this error in unity editor when the editor is not even running the scene..

[SFS - WARN] You are not connected. Request cannot be sent: Sfs2X.Requests.PingPongRequest

Seems like there is a bug with pingpongrequest where it doesn't stop when editor is stopped? will this happen on actual device causing mem leak?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: pingpongrequest

Postby Lapo » 24 Nov 2022, 16:07

Hi,
can you please provide more details about this issue?
What client API version are you using?
Also what Unity version are you using?
What steps should we use to reproduce the same problem?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Mrm83
Posts: 155
Joined: 17 Dec 2017, 04:02

Re: pingpongrequest

Postby Mrm83 » 30 Nov 2022, 15:19

Lapo wrote:Hi,
can you please provide more details about this issue?
What client API version are you using?
Also what Unity version are you using?
What steps should we use to reproduce the same problem?

Thanks


using latest client
using unity 2021.3.13f1

steps, not sure, it doesn't happen all the time. sometimes it happens sometimes it doesnt, so i can't provide any information.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: pingpongrequest

Postby Bax » 01 Dec 2022, 09:41

There's a chance that the issue is related to the fact that in Unity all SFS events are processed at once when the SmartFox.ProcessEvents method is called. We suspect that the ping-pong request (which is sent automatically when the lag monitor is enabled) is sent after the connection as already closed, but before the client processes the related event.
To make sure, you should check when the disconnection event is notified. I guess it occurs right after that error is printed in the Unity console.
Paolo Bax
The SmartFoxServer Team
Mrm83
Posts: 155
Joined: 17 Dec 2017, 04:02

Re: pingpongrequest

Postby Mrm83 » 12 Dec 2022, 14:55

Just reproduced the issue, dont know steps.
it happened after getting the following error during scene play.

[SFS - ERROR] Error handling data: Value was either too large or too small for an Int32. at System.Convert.ToInt32 (System.Double value) [0x0007a] in <56a9a46236d24d06871ab060564bb7ce>:0
at Sfs2X.Util.LagMonitor.DefaultLagMonitor.OnPingPong () [0x00019] in <5eca41b0feee402ba5eeb7b2d8ce4c51>:0
at Sfs2X.Controllers.SystemController.FnPingPong (Sfs2X.Bitswarm.IMessage msg) [0x0000c] in <5eca41b0feee402ba5eeb7b2d8ce4c51>:0
at Sfs2X.Controllers.SystemController.HandleMessage (Sfs2X.Bitswarm.IMessage message) [0x000b2] in <5eca41b0feee402ba5eeb7b2d8ce4c51>:0
at Sfs2X.Core.SFSProtocolCodec.DispatchRequest (Sfs2X.Entities.Data.ISFSObject requestObject) [0x000d3] in <5eca41b0feee402ba5eeb7b2d8ce4c51>:0
at Sfs2X.Core.SFSProtocolCodec.OnPacketRead (Sfs2X.Util.ByteArray packet) [0x00008] in <5eca41b0feee402ba5eeb7b2d8ce4c51>:0
at Sfs2X.Core.SFSIOHandler.HandlePacketData (Sfs2X.Util.ByteArray data) [0x00167] in <5eca41b0feee402ba5eeb7b2d8ce4c51>:0
UnityEngine.Debug:Log (object)
Sfs2X.Logging.Logger:Log (Sfs2X.Logging.LogLevel,string)
Sfs2X.Logging.Logger:Error (string[])
Sfs2X.Core.SFSIOHandler:HandlePacketData (Sfs2X.Util.ByteArray)
Sfs2X.Core.SFSIOHandler:OnDataRead (Sfs2X.Util.ByteArray)
Sfs2X.Bitswarm.BitSwarmClient:OnSocketData (byte[])
Sfs2X.Core.ThreadManager:ProcessItem (System.Collections.Hashtable)
Sfs2X.Core.ThreadManager:InThread ()
System.Threading.ThreadHelper:ThreadStart ()
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: pingpongrequest

Postby Bax » 12 Dec 2022, 17:08

It is not clear if the last error you reported and the first one (which is different) are related on your client. Do you see them both in your console? If yes, in which order?
Also, can you show when and how you enable the lag monitoring?
Thanks.
Paolo Bax
The SmartFoxServer Team
Mrm83
Posts: 155
Joined: 17 Dec 2017, 04:02

Re: pingpongrequest

Postby Mrm83 » 12 Dec 2022, 21:15

I see them both in editor.

[SFS - ERROR] Error handling data: Value was either too large or too small for an Int32. at System.Convert.ToInt32 (System.Double value) [0x0007a] in <56a9a46236d24d06871ab060564bb7ce>:0
occured once in editor while running.

[SFS - WARN] You are not connected. Request cannot be sent: Sfs2X.Requests.PingPongRequest
occurs in an infinite loop once editor is stopped.

I don't think this is my setup issue, never noticed it with previous editors. Upgraded to 2021 and started seeing this.

Following is called during Awake after logging into room in Scene3.
sfs.EnableLagMonitor(true);
sfs.AddEventListener(SFSEvent.PING_PONG, PingPongHandler);

private void PingPongHandler(BaseEvent evt) {
lastPing = (int)evt.Params["lagValue"];
}

scene1, no connection
scene2, connected to zone
scene3, connected to room
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: pingpongrequest

Postby Bax » 13 Dec 2022, 13:41

The fact that the "you are not connected" warning keeps showing in the console even after stopping the editor indicates that something is still running. I'd suggest to a "sfs.Disconnect()" call in the application quit listener.
Also, is the first error showing every time? Or did you just see it once?
Paolo Bax
The SmartFoxServer Team
Mrm83
Posts: 155
Joined: 17 Dec 2017, 04:02

Re: pingpongrequest

Postby Mrm83 » 13 Dec 2022, 15:19

if [SFS - ERROR] Error handling data: Value was either too large or too small for an Int32. at System.Convert.ToInt32 (System.Double value) [0x0007a] in <56a9a46236d24d06871ab060564bb7ce>:0 shows, [SFS - WARN] You are not connected. Request cannot be sent: Sfs2X.Requests.PingPongRequest will show.

Doesn't really make sense that I have to call sfs.disconnect on app quit even if it fixes the issue. This feels like a hack fix to fix something that is a result of some other error.

I believe the cause of the issue is if [SFS - ERROR] Error handling data: Value was either too large or too small for an Int32. at System.Convert.ToInt32 (System.Double value) , resulting in some other error causing disconnect not being called. This leads me to believe there is some underlying issue, and maybe some other subtle errors that is not easily noticed.

Why is SFS passing garbage to the cilent when client expects the value to to parse?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: pingpongrequest

Postby Lapo » 13 Dec 2022, 16:53

Doesn't really make sense that I have to call sfs.disconnect on app quit even if it fixes the issue. This feels like a hack fix to fix something that is a result of some other error.

Actually that would be a best practice. If someone quits the application leaving the network socket open could cause unwanted issues. This is a know issues since the early days in Unity and we've always recommended it, especially witjh random issues appearing exactly on application quit.

Why is SFS passing garbage to the cilent when client expects the value to to parse?


That's a good question but without a way to reproduce the problem it's quite difficult to fix.
Also, given we can't reproduce it in our test Examples it seems that this is dependent on what you're doing in your code as well. Maybe there is something specific that triggers it.

Can you help us understand how often the problem mainfests? At this point it's not even clear how frequent the problemi is.

If you can reproduce it fairly consistently we'd like to see your project (or a simplified version of it) and be able to see the issue in action ourselves.

Thanks
Lapo

--

gotoAndPlay()

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

Re: pingpongrequest

Postby Bax » 14 Dec 2022, 10:12

Mrm83 wrote:Doesn't really make sense that I have to call sfs.disconnect on app quit even if it fixes the issue. This feels like a hack fix to fix something that is a result of some other error.

I believe the cause of the issue is if [SFS - ERROR] Error handling data: Value was either too large or too small for an Int32. at System.Convert.ToInt32 (System.Double value) , resulting in some other error causing disconnect not being called. This leads me to believe there is some underlying issue, and maybe some other subtle errors that is not easily noticed.

I'm sorry but you are wrong. The error is not preventing the disconnection (we tested it), and calling sfs.Disconnect() on application quit is not a hack, but it is a mandatory requirement.
The reason is that when you leave play mode in the Unity Editor, Unity doesn't stop the internal threads launched by the SmartFox API (or any other script). This is a known issue (or maybe it is intended), and unless we adopt an hack inside the API (which we are not willing to do because of other impacts), you will need to use the OnApplicationQuit handler.

Not doing so will keep the connection to SFS alive when you exit play mode (check the server-side log), which in turn won't stop the lag monitoring from running.
We will make sure to clarify this in the documentation. So thank you for pointing out the issue.

This should explain why you keep seeing those warnings in the console when you leave play mode:
- the connection is not closed and the lag monitoring system keeps sending its requests
- after some time the client is flagged as idle and forcefully disconnected by the server
- the disconnection event is not processed because there's no more a main thread calling sfs.ProcessEvents(), as play mode was left
- not processing the disconnection, the lag monitor is not stopped and it keeps trying to send its requests to the server, but the action is rejected because there's no actual connection anymore, so a warning is printed in the Unity console

Now, we still have to understand why you get that [SFS - ERROR] Error handling data: Value was either too large or too small for an Int32.
Mrm83 wrote:Why is SFS passing garbage to the cilent when client expects the value to to parse?

SFS is not passing garbage, in fact this is the line causing the error, and it is not dependent on data sent by the server. All calculations happen on the client side.

Code: Select all

int lagValue = Convert.ToInt32((DateTime.Now - lastReqTime).TotalMilliseconds);

This is called every time a response to the lag monitor request is received by the SmartFox API. The only thing that could cause that error is a date far in the past set in lastRequestTime, but this is set to the current date every few seconds, before the lag monitor sends a new request to the server. In other words it is not clear how this could fail.

Given the error is not actually causing issues and you could ignore it, in our opinion it is caused by a strange race condition due to the connection not being closed when leaving play mode.
In fact I still have a question: is this occurring before or after you leave play mode in the Unity Editor?
We suggest to implement the OnApplicationQuit handler and check again if the error still occurs.

Code: Select all

void OnApplicationQuit()
{
   if (sfs != null && sfs.IsConnected)
      sfs.Disconnect();
}
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 53 guests