User connects to SFS, but can't login?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

User connects to SFS, but can't login?

Postby Sparticus » 08 Feb 2012, 14:45

Hey all,

If i start my smartfoxserver... everything works fine. Users can connect and login and everything works as it should.

However, I finally got around to testing at login that their username/password matches what i have in my database. I do this in my "LoginEventHandler" server side.

If they have an invalid username/password, I throw an error :

Code: Select all

SFSErrorData data = new SFSErrorData(SFSErrorCode.GENERIC_ERROR);
data.addParameter("Error id 1");
throw new SFSLoginException("Invalid Password.", data);


The client gets the error message and everything seems fine.

However, after entering invalid credentials a few times.... the server appears to hang... No one is able to log in anymore. I have to restart the server at this point to get it working again.

When it is hung, I notice the following :

1.) If a user tries to connect, they are successful.
2.) Client then sends login request.
3.) Server receives request and does nothing.... I have a "trace" at the top of the "LoginEventhandler" and it doesn't appear in the server log.

Here is what I see in the server log when someone tries to connect :

Code: Select all

08 Feb 2012 07:48:58,593 INFO  [SocketReader] bitswarm.core.SocketAcceptor     - Session created: { Id: 25, Type: DEFAULT, Logged: No, IP: ip_address:30387 } on Server port: 9933 <---> 30387
08 Feb 2012 07:48:58,593 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] v2.controllers.SystemController     - {IN}: Handshake
08 Feb 2012 07:48:58,687 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] v2.controllers.SystemController     - {IN}: Login


And normally at this point I see all my traces... instead it sits here and does nothing for maybe 15 seconds.... then the server disconnects the user.... you see this on the server log.

Code: Select all

08 Feb 2012 07:49:20,390 INFO  [SocketReader] bitswarm.sessions.DefaultSessionManager     - Session removed: { Id: 25, Type: DEFAULT, Logged: No, IP: ip_address:30387 }
08 Feb 2012 07:49:20,390 INFO  [SocketReader] bitswarm.core.SocketReader     - Socket closed: java.nio.channels.SocketChannel[closed]
08 Feb 2012 07:49:20,390 INFO  [Scheduler1-thread-1] bitswarm.sessions.DefaultSessionManager     - Session removed: { Id: 25, Type: DEFAULT, Logged: No, IP: ip_address:30387 }


Like I mentioned earlier, every user is unable to log in until i restart the server.

Any ideas?

Thanks!
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 08 Feb 2012, 15:19

Hmm, I "might" have figured it out. It doesn't appear to be happenign anymore... but I am not 100% sure yet.

At the beginning of the LoginEventHandler I create a new connection to the database. At the end of LoginEventHandler I close the connection.

However, if they enter an invalid user/password, I throw and error. And I do not close the connection before I throw the error.

The connection gets closed after I throw the error... so does that mean the connection never gets closed? And the reason the server is hanging is because there are no more connections available to connect to the database?

Thanks for any insight you can give :)
Jake-GR
Posts: 59
Joined: 28 Dec 2011, 22:52

Postby Jake-GR » 08 Feb 2012, 20:55

that does sound like what its doing, have you tried to change the Database Manager settings in the Admin Tool to double check?

(curious myself, as im just starting with database myself)

=-EDIT-=
found this little tid-bit on Oracle's site, a block that always gets run (even if an exception is thrown)
Important: The finally block is a key tool for preventing resource leaks. When closing a file or otherwise recovering resources, place the code in a finally block to ensure that resource is always recovered.

so if that is your problem, doing this 'should' work

Code: Select all

try {
    // grabs connection here
}
catch {
    // handle exceptions
}
finally {
    if (connection != null)
        connection.close();
}

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 32 guests