Accounts occasionally getting reset to default amounts
OriginalMadman opened this issue · 3 comments
Seems we have been getting hit with account resets lately (running Fe on 3 servers with same db - should be zero problems)...
We found this:
https://github.com/niccholaspage/Fe/blob/master/src/org/melonbrew/fe/database/databases/SQLDB.java#L168
I read it as "get exception during load -> return -1 -> reset account to default". A simple exception resets the account balance? doh!
Would you please have a look? I'm up to around a dozen players getting completely reset to default balance. No need to say more than it is an uproar and a headache, since there is no transaction logging :(.
There is no other particular message identified in the server log either...
EDIT: found a few instances of this:
<>2013-07-27 05:09:53 [SEVERE] at org.melonbrew.fe.listeners.FePlayerListener.onPlayerLogin(FePlayerListener.java:23)<
>
(I'll make a ticket too)
hi niccholaspage, I did some investigation, problem appears when people login to our least active servers, which was the reason I found the cause. The problem is in https://github.com/niccholaspage/Fe/blob/master/src/org/melonbrew/fe/database/databases/SQLDB.java#L56
.isClosed() is only guaranteed to return false, when you close the connection yourself. In this case the connection has been open too long and closed serverside.
In such cases isClosed() return false, but you get an exception when the ćonnection is used typically the loadAccountMoney(), and as a side effect side connection now knows it is closed isClosed() now returns true, causing the next saveAccount call to create a new connection and therefore delete the holdings.
I'm willing to help code the fix as well, and I'm open to suggestions. For our server I'll probably make a double try
try {
return loadAccountMoneyInternal();
} catch (SQLException e){
//Perhaps some logging here as well, or check if SQLException is really the Server Closed Connection thing
try {
return loadAccountMoneyInternal();
} catch (SQLException e){
e.printStackTrace();
return -1;
}
}
Only solves the loadAccountMoney, so might be needed in multiple functions....alternative options:
- Run a dummy sql command in checkConnection (creates overhead on all calls)
- Periodic task to run dummy sql to prevent the connection from closing
- Mark account in some way so when connection is established again it will write the delta to the database (or try persisting the delta account in file if needed) - Requires more work tho :P
If the statement fails, it has to return some value for a player's money. I also need a full stacktrace to figure this issue out.
This issue should have been fixed by 7cb9457.