Lost connection to database

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
GuilhermeVaz
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 17.08.2023, 19:25

Lost connection to database

Post by GuilhermeVaz »

Hi, I have had some problems related to losing connection with the database, I ended up doing a simple test with the MySQL crash and I noticed that when there is a loss of connection Zeos version 8.0 it automatically tries to reconnect to the database, as soon as the service stabilizes, I noticed that zeos opens several connections in sequence with the database, I managed to analyze about 2 thousand connections in 1 second when reconnecting to the database.
Checking the code in the ZDbcMySql unit, in the TZMySQLConnection class in the HandleErrorOrWarning procedure, I found the following code:
if AExceptionClass = EZSQLConnectionLost then
if Sender <> nil
then Sender.ReleaseImmediat(Sender, EZSQLConnectionLost(Error))
else ReleaseImmediat(Sender, EZSQLConnectionLost(Error))

every time there is a connection loss it goes into recursion in this piece of code thus generating N connections with the database, as I work with Web Servers, and a client with a bad connection ends up losing the connection when reconnecting it ends up generating many new connections and all with different ports for the same IP (the ports are usually sequential), and with that my MySQL ended up completely crashing and consequently crashing my entire WEB server.
Is there anything I can do to fix this? Is there any setting I can tweak so this doesn't happen?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Lost connection to database

Post by marsupilami »

Hello,

the code you mention usually doesn't do any reconnection. It is meant to clean up memory only. I seem to remember that there is / was a function in older mysql versions that tries to reconnect to the database, in the event of a connection loss. But I think that was changed in modern versions of MySQL.

Which version of MySQL and libmysql do you use? What happens if you use MAriaDB Connector/C? Could you try to describe some kind of example setup / code that allows us to replicate your problem?

Also you might want to take a look at this thread, where we discussed a similar problem: viewtopic.php?f=50&t=181749

Best regards,

Jan
Post Reply