Reconnection system issue

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Reconnection system issue

Postby M-D » 29 Oct 2012, 14:08

(From this topic)

Server: 2.3.0
Client 1.0.4

I was trying out the reconnection system, and after unplugging my network cable I get the following in my log:

Code: Select all

110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnDisconnect to 1 listeners
110143 [New I/O  worker #1] INFO sfs2x.client.bitswarm.BitSwarmClient - Attempting reconnection in 1000 msec
110143 [Thread-4] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: An existing connection was forcibly closed by the remote host
110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event reconnectionTry to 1 listeners
110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event connectionRetry to 1 listeners
[TEST] Connection retry: connectionRetry [ sfs2x.client.SmartFox@1a8fa0d1]
[TEST] getReconnectionSeconds(): 60
110143 [Thread-4] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
110145 [Thread-4] INFO sfs2x.client.core.EventDispatcher - Dispatching event ioError to 1 listeners
110262 [Thread-8] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: null
110262 [Thread-8] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
110262 [Thread-8] INFO sfs2x.client.core.EventDispatcher - Dispatching event ioError to 1 listeners
128192 [AWT-EventQueue-0] WARN sfs2x.client.SmartFox - You are not connected. Request cannot be sent: sfs2x.client.requests.ExtensionRequest@10f1f34a
130158 [AWT-EventQueue-0] WARN sfs2x.client.SmartFox - You are not connected. Request cannot be sent: sfs2x.client.requests.ExtensionRequest@50f800db

(The last two events are because of an extension request I did, the two entries starting with [TEST] are my own logs).

The CONNECTION_RETRY event is triggered (which is good I assume), however there is a bug in the system:
I never get the CONNECTION_RESUME / CONNECTION_LOST event (not at the start, but also not after the 60 second reconnect has passed).

I know that unplugging my network cable probably isn't the correct way to test the system, but I do expect to get the CONNECTION_LOST event (which I never seem to get).

The log also says this: "TCPSocketLayer: Socket error: null", not sure if this is a problem or not.

Is this a client bug?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Reconnection system issue

Postby rjgtav » 29 Oct 2012, 23:11

Hi,

It seems the API is firing a SOCKET_ERROR. Can you confirm that?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Reconnection system issue

Postby M-D » 30 Oct 2012, 09:21

Hi,

I checked, but I was already listening & logging SOCKET_ERROR events.
As it doesn't show up in the log, it seems that it wasn't triggered.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Reconnection system issue

Postby Lapo » 30 Oct 2012, 16:01

I know that unplugging my network cable probably isn't the correct way to test the system, but I do expect to get the CONNECTION_LOST event (which I never seem to get).

Problem is you're expecting something that is not going to happen (at least soon) :)

If you unplug the cable there's no way for the current connections to get closed because there's no network available. Closing a connection requires actual communication between the two ends. If you remove the cable and then check with your netstat utility (Win,Linux,OSX) you will find that all connections are in their previous states.
The OS eventually will probably shut down those connections after a certain amount of time (because they're idle), but it's difficult to predict when it will happen. It could take hours.

The API provide a killConnection() method that allow you to emulate a sudden disconnection.
Lapo
--
gotoAndPlay()
...addicted to flash games
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Reconnection system issue

Postby M-D » 30 Oct 2012, 16:35

Yes I understand, but judging by the logs the client lib has noticed the connection was lost (because it says it's going to attempt a reconnect):

Code: Select all

110143 [New I/O  worker #1] INFO sfs2x.client.bitswarm.BitSwarmClient - Attempting reconnection in 1000 msec
110143 [Thread-4] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: An existing connection was forcibly closed by the remote host
110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event reconnectionTry to 1 listeners
110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event connectionRetry to 1 listeners
[TEST] Connection retry: connectionRetry [ sfs2x.client.SmartFox@1a8fa0d1]
[TEST] getReconnectionSeconds(): 60


Now using the getReconnectionSeconds() function on the SmartFox lib I know the reconnection time span has been set to 60 seconds (right?).
And what I understand from the documentation I should get a CONNECTION_LOST after 60 seconds, because that's the time SFS tries to reconnect.

So from the client point of view I get the CONNECTION_RETRY, at which point I should freeze the GUI.
In the meanwhile SFS attempts to reconnect within the given time span, but what happens if it cannot reconnect?

Does it silently give up?


Or am I causing some kind of weird state by unplugging the cable?
Where part of the API knows it has disconnected (and attempts to reconnect) but another part doesn't know yet?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Reconnection system issue

Postby Lapo » 30 Oct 2012, 19:14

There are a few things that need to be clarified:

The reconnection time is a server-side setting that tells the server how long the User (and related Session) should be kept alive (as if nothing happened) before considering the client disconnected.
Should the User reach back the server within that timeframe, it will be transparently re-activated and no one will ever know.

The API technically don't keep bashing with connection attempts if an immediate error is returned. This is an extreme case, and should be seen more rarely, a full drop of the whole networking system.

There should be alot to be said here, but I want will try to keep it short: there are many different causes for a sudden disconnection and not of all of them can be dealt with. The complete shut down of the network interface is one but it is also the less likely to occur. Usually you can get a sloppy/unstable connection, a temporary traffic congestion on the ISP, a router error throughout the network path. These errors can be recovered with HRC because they usually don't last for too long (5-50 seconds).

We have experimented with an API prototype that attempts to fire new connections, if a socket error is immediately returned, but it didn't seem to solve the problem entirely and it introduced new ones. This approach must be thoroughly tested for each API and possibly multiple platforms (e.g. mobile vs desktop etc...) because it can have adverse effects.
I don't exclude that we'll be able to add this feature in a later update of the client API, for now HRC should be sufficient to cover most of common hiccups that can cause a game to be interrupted, for the full blown disasters (such as the NIC failure) we need to understand if there's a good way that works consistently on all the supported platforms.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 17 guests