poggit / libasynql

Asynchronous MySQL access library for PocketMine plugins.
https://poggit.github.io/libasynql
Apache License 2.0
132 stars 44 forks source link

Fixed reconnection to MySQL #34

Closed matcracker closed 2 years ago

matcracker commented 4 years ago

In the case of disconnection from MySQL, libasynql was unable to restore the connection due to the exception thrown. The following PR has the following fix: in case of a failed ping to the database, the thread tries to restore the connection until successful and continue the execution of the queries in the queue.

I also wanted to propose to set a maximum number of attempts after which to throw an exception or to end the thread execution, what do you think?

SOF3 commented 4 years ago

It would be nice to sleep for 2^n seconds for the nth time this loop is executed.

SOF3 commented 4 years ago

Furthermore, logging connection failure would be preferrable.

matcracker commented 4 years ago

So, you suggest me to increase the time of thread sleep every time it fails? Sounds good to me. In case of success the time is reset.

The connection failure is logged by default from mysqli.

SOF3 commented 4 years ago

You mean mysqli triggers a PHP warning implicitly? We probably want to suppress that with @. Those messages won't get logged to server.log.

matcracker commented 4 years ago

Right. I was thinking to use MainLogger but I don't like the idea, any other suggestions?

matcracker commented 4 years ago

Forget it, I can't use the MainLogger.

matcracker commented 4 years ago

Here is a result: image

SOF3 commented 4 years ago

Why do you use the server logger? There is the plugin logger...

matcracker commented 4 years ago

Why do you use the server logger? There is the plugin logger...

Because PluginLogger extends AttachableLogger and not AttachableThreadedLogger.

matcracker commented 4 years ago

I just thought that in case of more than one disconnected worker, each one will try to reconnect and consequently there will be a spam of messages. I should think another way, do you?

SOF3 commented 4 years ago

I just thought that in case of more than one disconnected worker, each one will try to reconnect and consequently there will be a spam of messages. I should think another way, do you?

I don't think that's a problem. The reconnection status of each thread is independent, and the logger detects the current thread name anyway.

In case of shaded virions, the thread name contains the shaded namespace, so it should be clear which plugin it came from.

dadodasyra commented 2 years ago

This would be awesome

SOF3 commented 2 years ago

please rebase the PR, looks good to me

matcracker commented 2 years ago

Done!