Exception when client library handles update after logout

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

Moderators: Lapo, Bax

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

Exception when client library handles update after logout

Postby M-D » 28 Mar 2013, 09:28

Hello,

When the client does a logout, and the server sends a UserVariableUpdate shortly after the client throws the following exception:

Code: Select all

TypeError: Error #1009: Cannot access a property or method of a null object reference.
 at com.smartfoxserver.v2.controllers::SystemController/fnSetBuddyVariables()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:1196]
 at com.smartfoxserver.v2.controllers::SystemController/handleMessage()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:129]
 at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150]
 at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54]
 at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:252]
 at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:111]
 at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:456]


We managed to fix this issue by doing the following check before doing a variable update on the user:

Code: Select all

// Make sure we still have this player connected
User user = [...];

if(user == null || user.isNpc()) {
   return;
}

ISession session = user.getSession();

// Is this guy connected?
if (!user.isConnected() || session == null || !session.isConnected() || !session.isLoggedIn()) {
   return;
}


But obviously its kinda strange that the server actually sends this data (maybe it should do a similar check?) and that the client tries to handle it even when not logged-in.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Exception when client library handles update after logou

Postby rjgtav » 28 Mar 2013, 15:31

Hello,

What Client API are you using? You can find the version you're using by tracing the version property of the SmartFox instance.
Please make sure you're using the latest one available at http://www.smartfoxserver.com/download/sfs2x#p=updates

Regarding your issue, which client is logging out? The user which UVs you're updating? Or that error happens when a client disconnects and you update the UVs of another user?

And when are you sending those UVs updates? On the UserDisconnectHandler?

Thanks
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.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Exception when client library handles update after logou

Postby Lapo » 28 Mar 2013, 15:39

Hi,
yes, in general it sounds weird that this happens, but it's not impossible. One reason for this could be related with a temporary slow down in the connection: when the logout is performed on the client side it takes some time for the update to get to the server side, meanwhile a UserVariable update was already coming from the server and hits the client in this "dirty" state.

There's not much that can be done about this because of the very asynchronous nature of the communication. It's also necessary to point out that the exception should do no harm to the client.

Thanks for reporting.
Lapo
--
gotoAndPlay()
...addicted to flash games
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Exception when client library handles update after logou

Postby M-D » 28 Mar 2013, 15:43

We're using version 1.1.6, which seems to be the last one.

It happens when a player is playing a game on our server and does a LogoutRequest().
This triggers a USER_LEAVE_ROOM / USER_DISCONNECT event, at which point the game is ended.
When the game ends we update some user variables (win / loss count for example) for all the players in the game.

I don't know if it crashes on the UV update of the disconnected player himself, or on a UV update of another player in the room.
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Exception when client library handles update after logou

Postby M-D » 28 Mar 2013, 15:47

Lapo wrote:[...]

There's not much that can be done about this because of the very asynchronous nature of the communication. It's also necessary to point out that the exception should do no harm to the client.

Thanks for reporting.


Well the problem is the exception occurs in the SFS library, so we can't capture it.
It does cause some harm though because it seems to freeze the client, although this might be because we catch unhanded exceptions.

Still, it does seem weird that my check to see if the player is connected / logged-in (on the session) seems to solve the issue.
Before the fix we could reproduce the error every single time and after the fix we don't get it anymore.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Exception when client library handles update after logou

Postby Lapo » 28 Mar 2013, 15:56

Yes, I don't understand how your code works either. Can you explain more?

As regards the exception: it shouldn't cause any damage because the Variable Update event bubbles from the socket engine up to the API internal handler where it causes an exception. This means that the actual update of the state of the client fails, but it's not a problem because the client isn't logged in any Zone. In other words the error should go undetected and cause no harm, but if you have the debugger Flash Player you will get the error window.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Exception when client library handles update after logou

Postby M-D » 28 Mar 2013, 16:16

Here is an example of what we do when the game ends. In the zone extension the following function is called when a player leaves and the game is ended
This will talk to our API to end the game, we get some information back (wins & losses for example) and we update the user variables (which contain this information).

Code: Select all

private void updateUserVariables()
{
   // Do API call for gameEnd
   UpdateResultData resultData = API.doCall([...]);

   // Update the users with the new information
   for (NewPlayerData playerData : resultData.getUpdatedPlayerInformation()) {
      Player player = this.players.getByUserId(playerData.getUserId());

      [...]

      // Update User Variables
      User sfsUser = player.getSmartFoxUser();

      // No point in updating NPC's
      if(sfsUser == null || sfsUser.isNpc()) {
         continue;
      }

      UserVariableManager.updateUserVariable(sfsUser, playerData);
   }
}


Now when we got the exception, I added the following (in between the ***stars**):

Code: Select all

private void updateUserVariables()
{
   // Do API call for gameEnd
   UpdateResultData resultData = API.doCall([...]);

   // Update the users with the new information
   for (NewPlayerData playerData : resultData.getUpdatedPlayerInformation()) {
      Player player = this.players.getByUserId(playerData.getUserId());

      [...]

      // Update User Variables
      User sfsUser = player.getSmartFoxUser();

      // No point in updating NPC's
      if(sfsUser == null || sfsUser.isNpc()) {
         continue;
      }

      **************************************************************************************
      ISession session = sfsUser.getSession();

      // Are we sure this guy is still connected?
      if (!sfsUser.isConnected() || session == null || !session.isConnected() || !session.isLoggedIn()) {
         continue;
      }
      **************************************************************************************

      UserVariableManager.updateUserVariable(sfsUser, playerData);
   }
}


Now we don't get the exception anymore.
Maybe its because of the 'session.isLoggedIn()' check?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Exception when client library handles update after logou

Postby Lapo » 29 Mar 2013, 16:10

Here is an example of what we do when the game ends. In the zone extension the following function is called when a player leaves and the game is ended. This will talk to our API to end the game, we get some information back (wins & losses for example) and we update the user variables (which contain this information).

I think there's a problem with the logic. What exactly do you mean when you say that you're updating variables when the player leaves?
What server event are you listening for?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 21 guests