Page 1 of 1

Flash Client Api Blows Up

Posted: 28 Sep 2017, 06:10
by ekrem5353
Hi,

User adding error, After we developed our mobile apps with unity. Sometimes when user sends subscribe the group request which he or she already subscribed to flash clients who subscribed to same group blow up they get this error



TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.smartfoxserver.v2.entities.managers::SFSUserManager/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/managers/SFSUserManager.as:78]

at com.smartfoxserver.v2.entities::SFSRoom/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/SFSRoom.as:439]

at com.smartfoxserver.v2.controllers::SystemController/fnUserEnterRoom()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:313]

at com.smartfoxserver.v2.controllers::SystemController/handleMessage()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:137]

at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150]

at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54]

at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:254]

at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:113]

at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:474]

6:13

RangeError: Error #2006: The supplied index is out of bounds.

at flash.utils::ByteArray/writeBytes()
at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:242]

at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:113]

at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:474]


after that they can always get The supplied index is out of bounds exception when server sends anything


Thanks...

Re: Flash Client Api Blows Up

Posted: 28 Sep 2017, 06:58
by Lapo
Hi,
it would help to know the version of the AS3 API in use and how to reproduce the problem.

In particular you talked about subscribing to an already subscribed group, but the error reported here is triggered by another User entering the Room where the player is.

I need to better understand the sequence of requests that cause this and if it's reproducible at will or not.

Thanks

Re: Flash Client Api Blows Up

Posted: 28 Sep 2017, 08:35
by ekrem5353
Hi,

it is reproducable and last version of flash api is being used. It is also reproducable with SmartFox 2.13 and SmartFox 2.11. When unity(android) user sends subscribe request while it is already subscribed to that group all the flash clients get this error and after that every time server sends anything they(flashclients) get null pointer exceptions.

Thanks

Re: Flash Client Api Blows Up

Posted: 28 Sep 2017, 10:33
by ekrem5353
Hi,

Can you add try catch here on flash client api


************************original
public function addUser(user:User) : void

{

if(this._usersById.hasKey(user.id))

{

this._smartFox.logger.warn("Unexpected: duplicate user in UserManager: " + user);

}

this._addUser(user);

}


*********************with try catch



public function addUser(user:User) : void

{

try

{

if(this._usersById.hasKey(user.id))

{

this._smartFox.logger.warn("Unexpected: duplicate user in UserManager: " + user);

}

this._addUser(user);

}

catch(error:Error)

{

}

}


like this

Thanks

Re: Flash Client Api Blows Up

Posted: 28 Sep 2017, 14:41
by Lapo
Does this happen only when an Android(Unity) client does that or does can it be triggered by any client?

I would find it really odd that only Android could trigger the problem because technically the Subscribe Request is the same, regardless of the platform.

Another problem I see is that a SubscribeRoomGroupRequest will trigger a ROOM_GROUP_SUBSCRIBE or ROOM_GROUP_SUBSCRIBE_ERROR events. But in your stack trace you are showing an error during a USER_ENTER_ROOM error.
I am not sure how these two are correlated.

More importantly if a client attempt to subscribe twice to a group it will trigger a ROOM_GROUP_SUBSCRIBE_ERROR and nothing will happen. (I mean nothing internally to the API, such as changes to the data structures etc...)

So I am not too sure I really understand what is going on here... Can you describe how this happens step by step?

Thanks

Re: Flash Client Api Blows Up

Posted: 28 Sep 2017, 14:55
by ekrem5353
Hi,

We can trigger it with unity editor too. I think it can be triggered from any platform. We send subscribe roomgroup request and then join room request and subscribe roomgroup request again.

Code: Select all

public function addUser(user:User) : void
     {
        if(this._usersById.hasKey(user.id))  // Comment1:
        {
           this._smartFox.logger.warn("Unexpected: duplicate user in UserManager: " + user);
        }
        this._addUser(user);
     }


after that continuously get null pointer exception


Comment1:// When we debug it at this line it gets null pointer exception in all the flash clients, user is not null and user.id is available in _usersById


Thanks

Re: Flash Client Api Blows Up

Posted: 28 Sep 2017, 17:14
by Lapo
Sorry but we can't reproduce this and in particular there's the fact that you cannot join a group more than one time.
If you attempt to do it you will just get an error back.

I've tested with two flash clients, by joining a group and then a Room.
Then I launch another user join the same group 4 times and then join the same Room.
No errors, nothing.

If that's not how it should be tested then please be very specific about the sequence of commands.

thanks

Re: Flash Client Api Blows Up

Posted: 15 Jan 2018, 16:11
by rewb0rn
Hello,

we are seeing the exact same error "Error #1009: Cannot access a property or method of a null object reference." in SFSUserManager.addUser().

I see the error only very sporadically, maybe every 100th time I log in on the server. We are not using any groups (I don't even know what this is) and we are not having Unity clients, so the reason seems to be different. The error breaks the flow and as a consequence, communication with the smartfox is not possible afterwards, no updates from Smartfox seem to be sent or received on the client, i.e. the session is broken and the user has to reload the game. Due to the rarity of this bug we have not much details, unfortunately. The client API version is 1.7.5, so we are up to date, server version is 2.11.

Is it possible to catch this error on the API level? The error is happening in the .swc loop and not in our code so we can not catch it.

Re: Flash Client Api Blows Up

Posted: 16 Jan 2018, 08:33
by Lapo
Hi,
we can try/catch exceptions and see if it helps.
It would help to see a stack trace of the debug version of the error, just to understand exactly what is the call tree.

The method in question is painfully simple:

Code: Select all

      public function addUser(user:User):void
      {
         if (_usersById.hasKey(user.id))
            _smartFox.logger.warn("Unexpected: duplicate user in UserManager: " + user)
            
         _addUser(user)
      }

The objects being called (_usersById and _smartFox) are global and they're created much earlier, before any connection exists, so it is pretty bizarre that a NP error is raised.

In any case I suggest you send us an email with a reference to this thread (use our support@...) and we'll send you and update to test with the try/catch around that code.

Hope it helps

Re: Flash Client Api Blows Up

Posted: 16 Jan 2018, 09:28
by rewb0rn
Hi Lapo,

thanks for your message! Next time I see the error I will copy the stack trace and send the email, along with any other details I might spot.

Kind regards,
Ruben

Re: Flash Client Api Blows Up

Posted: 16 Jan 2018, 16:18
by Lapo
Ok, however if you want to try the patch you can send us an email anyways. I wasn't meaning to wait the next occurrence, especially if it takes a while. In any case the debug stack trace would help for sure! :)

thanks

Re: Flash Client Api Blows Up

Posted: 17 Jan 2018, 11:55
by rewb0rn
Okay no worries, I got the error earlier then expected :)

Here is the stack trace:

Code: Select all

com.smartfoxserver.v2.entities.managers::SFSUserManager/addUser at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/managers/SFSUserManager.as:78
com.smartfoxserver.v2.entities::SFSRoom/addUser at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/SFSRoom.as:439
com.smartfoxserver.v2.controllers::SystemController/fnUserEnterRoom at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:313
com.smartfoxserver.v2.controllers::SystemController/handleMessage at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:137
com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150
com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54
com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:254
com.smartfoxserver.v2.core::SFSIOHandler/onDataRead at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:113
com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData at /Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:474


In the attachment you see the variable analysis for the classes in question, I hope it helps. I have expanded all entries that were not unreasonably long. If you require details about some subclass that is hidden in the screenshot, just tell me and I will expand it the next time I see the error. I will also send an email, just in case.

Thanks and kind regards,
Ruben

Re: Flash Client Api Blows Up

Posted: 17 Jan 2018, 13:17
by rewb0rn
Ok I am shooting a wild guess here:

It looks like the _smartfox variable is null and the _smartfox variable is trying to be accessed when a user duplicate is found. The error pops up immediately after connecting to the server, possibly before the _smartfox variable is initialized. So maybe another user connects just in the same moment I am receiving the list of users from the server. Due to a race condition my client receives the user twice, once in the initial list and once in an update that was broadcasted to the room afterwards. Now the SFS sees a duplicate and tries to log a warning, but the SFS object is not there and we have the exception.

Suggested fix in API:

Code: Select all

 public function addUser(user:User):void
      {
         if (_usersById.hasKey(user.id) && _smartFox != null)
            _smartFox.logger.warn("Unexpected: duplicate user in UserManager: " + user)
           
         _addUser(user)
      }
 

Re: Flash Client Api Blows Up

Posted: 17 Jan 2018, 14:41
by Lapo
The fact is that the _smartFox object cannot be null, ever. It represents the instance of your SmartFox object and as such it cannot not exist :)

Similarly the usersById object is initialized before a connection is made.
I think a full stack trace could help seeing where the problem could be.

Re: Flash Client Api Blows Up

Posted: 17 Jan 2018, 15:42
by rewb0rn
Hi Lapo,

thanks, have you seen the screenshot I attached? _smartFox is definitely null there. Also thanks for the updated client API!

Kind regards,
Ruben