New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 Warning when connection has been expired using persistent connection to Mysql Server #3423

Closed
rafrsr opened this Issue Apr 30, 2014 · 10 comments

Comments

Projects
None yet
7 participants
@rafrsr

rafrsr commented Apr 30, 2014

I got the following warning using persistent conection to mysql server when the connection has ben expired

Warning (2): PDO::__construct(): MySQL server has gone away [ROOT\vendor\cakephp\cakephp\src\Database\Driver\PDODriverTrait.php, line 45]

I have tried setting the wait_timeout to the max value in the /etc/my.cnf file ie;

wait_timeout=31536000

this happen when

  • restart mysql server
  • after long time of inactivity

Is possible catch the PDOException and reconnect witouth warning?

@markstory

This comment has been minimized.

Member

markstory commented Apr 30, 2014

Anything is possible, perhaps you could put a pull request together for this? I personally never use persistent connections because of issues like this.

@markstory markstory added this to the 3.0.0 milestone Apr 30, 2014

@markstory markstory added the RFC label Apr 30, 2014

@ravage84

This comment has been minimized.

Member

ravage84 commented Jul 4, 2014

Not sure if everybody wants his connection being reconnected silently...
If a server goes away or the PDO decides it's time to let go it's not without reason... 💭

@markusramsak

This comment has been minimized.

Contributor

markusramsak commented Jul 8, 2014

I agree with @ravage84 and @markstory
persistent connections don't have any big advantage. You simply cannot have a reliable connection all the time. It leads to too much problems.
@rafrsr Why do you even use it? Is there a particular reason or big advantage you see?

@markstory

This comment has been minimized.

Member

markstory commented Jul 9, 2014

Closing as there is a simple solution to this issue - don't use persistent connections.

@markstory markstory closed this Jul 9, 2014

@lorenzo

This comment has been minimized.

Member

lorenzo commented Jul 9, 2014

The simplest solution is to increase the timeout both in mysql and in php settings. There is a good case for persistent and long living connections, which is worker processes in cli.

@dilab

This comment has been minimized.

Contributor

dilab commented Jan 13, 2017

@lorenzo
Agree.

But I think by configuring the mysql and php setting value is like denying the real issue. In some cases, it is almost impossible to know how long the connection will be idle.

@dilab

This comment has been minimized.

Contributor

dilab commented Jan 13, 2017

In a long running process (worker). Even the connection is not persistent, it will encounter MySQL server has gone away kind of issue when idle time > wait_time.

@lorenzo , should we have an option to allow CakePHP to reconnect ?

@dilab

This comment has been minimized.

Contributor

dilab commented Jan 13, 2017

Just a note for anyone who is facing the same issue.

We are using a hack blow. Before each job is processed, we manually reconnect the database:

$connection = ConnectionManager::get('default');

$connection->disconnect();

$connection->connect();

@josegonzalez

This comment has been minimized.

Member

josegonzalez commented Jan 13, 2017

I believe sidekiq and djjob in the Rails world have a hack like the above that resets connections - though I don't think its the default.

@lorenzo

This comment has been minimized.

Member

lorenzo commented Jan 13, 2017

@dilab adding as an option, off by default sounds good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment