Invalid Socket Error

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

dwilday
Posts: 6
Joined: 09 Nov 2011, 01:00
Location: Seattle, WA
Contact:

Invalid Socket Error

Postby dwilday » 16 Dec 2011, 19:43

Hi,
I'm working on a game that will have a fairly heavy load. The client wants the Lobby and Game Servers separated so that we can scale them as needed (as well as a few other reasonable points). The way we're accomplishing this is that we're having the Lobby Server act as a match maker for the users at which point it sends them back a unique room name and the IP address of the game server they will be joining. At this point each player disconnects from the Lobby Server and connects to the new server.

This all seems to work fairly well.

A problem arises when I attempt to test it under a reasonably heavy load. I've written a small flash client that creates hundreds of simultaneous connections and then keeps feeding it a set of new connections every 5 seconds. The game server plays a mock game with each of the players and the players disconnect when they are done with the game. After running for a minute or so with no issues I recieve an error in the flash client stating that an operation is being attempted on an invalid socket.

Code: Select all

Error: Error #2002: Operation attempted on invalid socket.
   at flash.net::Socket/internalClose()
   at flash.net::Socket/close()
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/disconnect()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:273]
   at Function/<anonymous>()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/SmartFox.as:1104]
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at SetIntervalTimer/onTimer()
   at flash.utils::Timer/_timerDispatch()
   at flash.utils::Timer/tick()



If I dismiss this and let this continue to run ultimately one of the java processes will consume all off the available CPU.
Whether these issues are related or not they both seem to pose a problem.

Any ideas as to what's going wrong?


Thanks,
Daniel
dwilday
Posts: 6
Joined: 09 Nov 2011, 01:00
Location: Seattle, WA
Contact:

Anyone?

Postby dwilday » 20 Dec 2011, 18:59

I thought I was making some headway but I'm still left with this error, a bunch of accumulating ghost connections (presumably related), and a heap of memory growth.

Anyone have any insights to offer?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 20 Dec 2011, 21:30

What I don't understand is... is this a problem happening to your players or is an issue with your local test app?
To me it looks as if the local test app is running short of resources or there's some other bug... or maybe you're pushing the FlashPlayer a little too much with all those sockets.
Lapo
--
gotoAndPlay()
...addicted to flash games
dwilday
Posts: 6
Joined: 09 Nov 2011, 01:00
Location: Seattle, WA
Contact:

Postby dwilday » 20 Dec 2011, 21:41

Lapo wrote:What I don't understand is... is this a problem happening to your players or is an issue with your local test app?
To me it looks as if the local test app is running short of resources or there's some other bug... or maybe you're pushing the FlashPlayer a little too much with all those sockets.


Those are definitely on my list of questions as well. I'm throwing this question out here into the wild as one of my many attempts to unravel this riddle.

One thing I did notice is that apparently our installation of SFS2X never had the RC3 patch applied... so we've been running RC1. Ouch. Here's to hoping that replacing that and swapping out the AS3 library will clear things up.
playline
Posts: 7
Joined: 07 Nov 2014, 18:02

Re: Invalid Socket Error

Postby playline » 07 Nov 2014, 19:02

We get this error as well:

Code: Select all

Error #2002: Operation attempted on invalid socket.
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/disconnect()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:284]
   at Function/<anonymous>()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/SmartFox.as:1343]
   at Function/<anonymous>()
   at SetIntervalTimer/onTimer()
   at flash.utils::Timer/tick()

We are building a mobile game in Air. This happens on all iOS devices. I don't know about Android.
To deal with losing wifi signal, we are listening the NetworkInfo for changes. When we detect a network change, we recreate the socket connection because there is no other way of dealing with this.
The error appears when the former connection was mobile and the new one is wifi.


Also we have discovered another issue:
On iOS, if you keep an open socket connection without making any calls (let's say 10 seconds), the answer of the first call we make after this "dead" time will be received with a delay that can go up to an incredible 60 seconds. We compiled the sample SpaceWar app as well for the iOS and it also happens in that one. Probably the operating system chokes the TCP tunnel if no calls are being made. To deal with this we created a keepAlive call that we are triggering once every 200ms.
Do you think it's OK?
Can you investigate this?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid Socket Error

Postby Lapo » 07 Nov 2014, 20:34

Recreating the connection object (SmartFox) makes perfect sense, in fact it is the proper way.

Probably the operating system chokes the TCP tunnel if no calls are being made. To deal with this we created a keepAlive call that we are triggering once every 200ms.
Do you think it's OK?

No. Every 200ms is way too much and you will be wasting bandwidth. One keepalive message every 4-5 seconds should work just fine.

In any case this is not normal under iOS, at least native iOS. There's no problem with leaving the connection idle for minutes.

Can you investigate this?

We can take a look although I have little hope that we can do anything about as this is out of our control. What the AIR runtime does with TCP connections is not accessible to Actionscript developers. Unless there are specific AIR runtime settings that you can configure before exporting? Is it possible? Have you checked?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
playline
Posts: 7
Joined: 07 Nov 2014, 18:02

Re: Invalid Socket Error

Postby playline » 10 Nov 2014, 13:11

Lapo wrote:Recreating the connection object (SmartFox) makes perfect sense, in fact it is the proper way.


OK. But that triggers the mentioned error which is detected by iOS which forcefully closes the app. Is there a way to try -> catch

Code: Select all

BitSwarmClient/disconnect()
?
I see it is called with a delay so it's hard for me to catch it.

What are your thoughts about this?

Cheers,
Irinel
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid Socket Error

Postby Lapo » 10 Nov 2014, 13:51

It would be great if you could clarify how exactly this error is triggered.
I understand that you're listening for NetworkInfo changes and when you detect a network switch you create a new connection.

But how exactly is the other error triggered? Is it due to the network switch? If so, does it fire immediately?
Or is it due to your game logic trying to send data to the former connection?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
playline
Posts: 7
Joined: 07 Nov 2014, 18:02

Re: Invalid Socket Error

Postby playline » 11 Nov 2014, 12:43

Lapo wrote:It would be great if you could clarify how exactly this error is triggered.
I understand that you're listening for NetworkInfo changes and when you detect a network switch you create a new connection.

But how exactly is the other error triggered? Is it due to the network switch? If so, does it fire immediately?
Or is it due to your game logic trying to send data to the former connection?

Thanks


-AIR on iOS 8 with both mobile and wifi connections (active one: wifi):
1. enter the app, create socket connection
2. open the iOS control drawer and turn off wifi. wait with the drawer opened until the new socket is created
3. the OS is triggering network changed event so we recreate the socket connection on mobile data
4. close the drawer for the app to gain focus.
5. make a socket call
6. open the iOS control drawer and turn on wifi. wait with the drawer opened until the new socket is created
7. the OS is triggering network changed event so we recreate the socket connection on wifi
8. close the drawer once the socket is fully initialized (connection + login)
9. BOOM, the error appears. On a release build this is detected by iOS which closes the app to prevent the device from freezing.

The steps I just wrote are so you can reproduce the crash 100% of the time.
I know that forcefully killing the wifi is bad for the HRC but this crash still needs to be addressed because, this also happens during normal reconnections.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid Socket Error

Postby Lapo » 11 Nov 2014, 17:27

Thanks.
Strangely the line numbers where the error originates point to a call to the BlueBox connection. Are you aware that you're using an HTTP connection?
Lapo

--

gotoAndPlay()

...addicted to flash games
playline
Posts: 7
Joined: 07 Nov 2014, 18:02

Re: Invalid Socket Error

Postby playline » 12 Nov 2014, 12:21

Code: Select all

         _socket = new SmartFox();
         
         _socket.addEventListener(SFSEvent.CONNECTION, handleConnectionStatus, false, 0, true);
         _socket.addEventListener(SFSEvent.CONNECTION_ATTEMPT_HTTP, handleConnectionHTTPAttempt, false, 0, true);
         _socket.addEventListener(SFSEvent.CONNECTION_LOST, handleConnectionLost, false, 0, true);
         _socket.addEventListener(SFSEvent.CONNECTION_RETRY, handleConnectionRetry, false, 0, true);
         _socket.addEventListener(SFSEvent.CONNECTION_RESUME, handleConnectionResume, false, 0, true);
         _socket.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, handleConnectionLost, false, 0, true);
         _socket.addEventListener(SFSEvent.EXTENSION_RESPONSE, handleExtensionResponce, false, 0, true);
         _socket.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, handleUserVarsUpdate, false, 0, true);
         _socket.addEventListener(SFSEvent.SOCKET_ERROR, handleSocketError, false, 0, true);
         _socket.addEventListener(SFSEvent.LOGIN, handleLogIn, false, 0, true);
         _socket.addEventListener(SFSEvent.PING_PONG, handlePingPong, false, 0, true);
         _socket.addEventListener(IOErrorEvent.IO_ERROR, handleConnectionLost, false, 0, true);
         
         var configData:ConfigData = new ConfigData();
         
         configData.host = _host;
         configData.port = 9933;
         configData.useBlueBox = true;
         configData.zone = "CoralGame1";
         configData.debug = false;
         
         _socket.connectWithConfig(configData);

So configData.useBlueBox = true; means I'm forcing the connection to use BlueBox?
I thought it just enables the BlueBox option in case it automatically detects that a socket connection cannot be made.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid Socket Error

Postby Lapo » 12 Nov 2014, 14:33

Yes, exactly you're right. It doesn't force the HTTP connection, it only renders it available as a "second chance" if the socket connection fails.

Since your error traces point to the BlueBox code I was wondering what else was going on.
You should probably monitor the SmartFox.connectionMode property to see in each connection attempt what type of connection was used.

Let me know what you find, it could help understanding this case better.
Lapo

--

gotoAndPlay()

...addicted to flash games
playline
Posts: 7
Joined: 07 Nov 2014, 18:02

Re: Invalid Socket Error

Postby playline » 12 Nov 2014, 15:33

Lapo wrote:Yes, exactly you're right. It doesn't force the HTTP connection, it only renders it available as a "second chance" if the socket connection fails.

Since your error traces point to the BlueBox code I was wondering what else was going on.
You should probably monitor the SmartFox.connectionMode property to see in each connection attempt what type of connection was used.

Let me know what you find, it could help understanding this case better.


_socket.connectionMode is al the time "socket".
I tried with useBlueBox both true and false;
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid Socket Error

Postby Lapo » 12 Nov 2014, 18:34

Just to clarify what is the version of the API you're using?
( see SmartFox.getVersion() )
Lapo

--

gotoAndPlay()

...addicted to flash games
playline
Posts: 7
Joined: 07 Nov 2014, 18:02

Re: Invalid Socket Error

Postby playline » 12 Nov 2014, 19:09

Lapo wrote:Just to clarify what is the version of the API you're using?
( see SmartFox.getVersion() )

AS3 client uses: 1.2.5
Server uses: 2.9

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 7 guests