• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Linux TFS 1.2 Not Stable on Ubuntu [SOLVED]

Nazubal27

New Member
Joined
Mar 6, 2013
Messages
45
Reaction score
4
Location
Canada
Hey there, thanks in advance if you have any advice.

I'm running my server on an Ubuntu machine (14.04) and it works fine for hours at a time but it freezes randomly for random amounts of time (minutes to hours).

It runs just fine for a while but eventually it stops responding, and I get kicked from the server and cannot re-login (it doesn't say that I cannot connect to the server just sits saying "Your character list is being loaded").

Problem is the server still appears to be running, and it outputs no errors in the terminal. It shows up when I run 'top' but shows its using 0% of my CPU.

So it seems like its just hung and needs to be restarted, but then starts working again at some point in the future (sometimes minutes, sometimes hours) without restarting it.

Could other things to note:
- otservlist.org still shows that my server is online too.
- Also I cannot replicate this freeze on my windows machine that I develop on.

So does anyone have any advice on how I can debug this problem? Could an error be being thrown and the server doesn't print it? Is there any place in the source code I should add some couts to help me debug?
 
Turns out an error is being printed out, but only after the server starts responding.

The error I'm getting is

[Error - mysql_real_query] Query: SELECT `id`, `amount`, `price`, `itemtype`, `player_id`, `sale` FROM `market_$
Message: Lost connection to MySQL server during query

The lost connection error shows up with many different queries so I dont think its the specific query that's causing the problem.

It appears to happen after the connect has been sitting open for a long period of time (possibly without being used). Possibly the server thinks the connection is still open and the database server has closed the connection already.
 
SOLVED!

So my problem was caused by a connection to the mysql server not working if it hasn't been used in a while. So the next query attempt will timeout but the server deals with this issue by sticking the execute query code in a loop that reattempts in-case of this kind of failure. The problem was my timeout value was set to be very high for some reason.

I added some code to the database.cpp file so explicitly set the connection timeout value to be 2 seconds. So the query error still occurs but it times out after only 2 seconds and then the query is ran again and it succeeded the next time.

So under

Code:
  // automatic reconnect
    my_bool reconnect = true;
    mysql_options(handle, MYSQL_OPT_RECONNECT, &reconnect);

in the 'bool Database::connect()' method I added:

Code:
    unsigned int conn_timeout = 2;
    mysql_options(handle, MYSQL_OPT_CONNECT_TIMEOUT, &conn_timeout);
    unsigned int timeout = 1;
    mysql_options(handle, MYSQL_OPT_WRITE_TIMEOUT, &timeout);
    mysql_options(handle, MYSQL_OPT_READ_TIMEOUT, &timeout);
 
Back
Top