NULL user objects

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

NULL user objects

Post by Blank_101 »

When cycling through the active user list sometimes I come across a null user. These null users can hang around in memory for minutes at a time. These null users create all sorts of problem in my extensions. When I wrote the script I didn't account for the server to be holding a null user object. Is there any reason why the server isn't getting rid of these null user objects?

I run sfs version 1.4.2.

Thanks,

Blank_101
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

When cycling through the active user list sometimes I come across a null user.
Client side or server side?
How do you get the user list?
Lapo
--
gotoAndPlay()
...addicted to flash games
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

Post by Blank_101 »

Lapo wrote:
When cycling through the active user list sometimes I come across a null user.
Client side or server side?
How do you get the user list?
Server side. I keep a list of active users on my zone extension.

To populate the list I cycle through all users on extension init():

Code: Select all

for (var i = zone.getChannelList().iterator(); i.hasNext(); ) {
	var user = _server.getUserByChannel(i.next());
	if (user != null) {
		userList[user.getUserId()] = user;
	}
}
After that everytime a user leaves or enters the zone I just adjust the list as needed.

Another way I cycle through the active users list:

Code: Select all

var recipients = [];
var zone = _server.getCurrentZone();
var roomList = zone.getRooms();
for (var i in roomList) {
	var userList = roomList[i].getAllUsers();
	for (var o in userList) {
		recipients.push(userList[o]);
	}
}
All of the above methods of cycling through the user lists have resulted in a null user object coming up at some time or another. And when one of the user retrieval methods finds a null user they all do, so I'm assuming the problem lies with the server not handling a null user object properly.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I am not sure if I understand:
this code is correct

Code: Select all

 for (var i = zone.getChannelList().iterator(); i.hasNext(); ) {
   var user = _server.getUserByChannel(i.next());
   if (user != null) {
      userList[user.getUserId()] = user;
   }
}
You have to check for null users because you're trying to see if a certain socket channel corresponds to a User. This is not necessarily true, so your check is correct.

Does the problem appear with the 2nd snippet of code?
Lapo
--
gotoAndPlay()
...addicted to flash games
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

Post by Blank_101 »

Lapo wrote:I am not sure if I understand:
this code is correct

Code: Select all

 for (var i = zone.getChannelList().iterator(); i.hasNext(); ) {
   var user = _server.getUserByChannel(i.next());
   if (user != null) {
      userList[user.getUserId()] = user;
   }
}
You have to check for null users because you're trying to see if a certain socket channel corresponds to a User. This is not necessarily true, so your check is correct.

Does the problem appear with the 2nd snippet of code?
The problem does appear in the 2nd snippet of code. Also, the 1st snippet can throw the null user error as well. They both throw the same error when a null user is present on the server.
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

Post by Blank_101 »

Still looking for a solution to this.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I've investigated some more.

1) In the first code snippet, as I already mentioned, you have to check for null objects because you're retrieving Users from their SockerChannels. It's not guaranteed that a SocketChannel has its corresponding User object, hence you should check for null values being returned

2) In the 2nd snippet the culprit should be the getAllUsers() method, however at the moment it's not really clear why this should happen.
As a workaround you can simply check for null values and discard them.
In order to go hunting for possible bugs we'd like to have more infos about the issue.

Can you reproduce the problem?
Does this happens with low traffic?
Does it seem to be happening after a certain amount of time?

The more info you can provide the quicker we can restrict the "hunt zone" and provide a solution

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

Post by Blank_101 »

Ok, the problem came up again yesterday. I actually managed to pinpoint the room the null user was located. I ran this code to find the culprit in the room:

Code: Select all

for (var i in userList) {
trace(userList[i]);
}
Sure enough I got an output similar to this:

Code: Select all

...
user
user
user
user
null
user
user
user
...
The above user list came from a room retreived by the room.getAllUsers() method.

To answer your questions:
Lapo wrote:Can you reproduce the problem?
No.
Lapo wrote:Does this happens with low traffic?
I have only seen this problem occur during higher traffic. It also may be a worth while note that the extension handler queue sometimes reaches 8K messages during high traffic in which case messages start getting dropped. We have a custom login as well.
Lapo wrote:Does it seem to be happening after a certain amount of time?
No, it's random as far as I can tell. Sometimes the problem doesn't come up for days at a time. Sometimes it will come up multiple times within a few hours.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Next time it happens, please launch the admin tool and check the room that seems to have a "null" user. Let me know if this affects the tool in any way, or if you see anything wrong (i.e. wrong number of users, or a "null" user or anything like that)

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

We've been running a stress test where 300 users where joining 10 rooms at a time, sending messages and objects and leaving the rooms at a very fast rate.
While this was running an extension was continuously monitoring the user list to trap possible NULL user objects.

Nothing was found.
The test was run on the current server engine (1.5.x). I believe it shouldn't be different from the 1.4.2 that you're using (at least in the parts interested by this test)

If you have more details let us know
Lapo
--
gotoAndPlay()
...addicted to flash games
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

Post by Blank_101 »

An update:

The problem came up again the other day. I managed to isolate the room in which the null users were located. I came up with 3 null user instances inside my main auto-join room. I loaded the admin tool like you asked and checked the auto-join room. The admin tool would only load the user list up to the point of a null user being found then the script would stop. User list updates after that point would still register, but the room info would never load and the "busy bar" at the bottom right just kept going.

The null users remained in the auto-join room indefinitely as far as I could tell. I left the server on for 2 days after the null users popped up and they never went away.
Blank_101
Posts: 43
Joined: 02 Dec 2006, 18:30

Post by Blank_101 »

Another update: We upgraded to sfs 1.5.5 and a null user came up again.
Post Reply