Skip to content
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

PDOPool does not reconnect on connection timeout. #4141

Closed
intellent opened this issue Apr 8, 2021 · 3 comments
Closed

PDOPool does not reconnect on connection timeout. #4141

intellent opened this issue Apr 8, 2021 · 3 comments
Labels

Comments

@intellent
Copy link

1. What did you do? If possible, provide a simple script for reproducing the error.

Created a MySQL PDOPool to fetch connections with PDOPool::get() and put them back with PDOPool::put($con) after the HTTP response has been served. wait_timeout of the DBMS is very low (60 seconds), but this problem also occurs with larger values, only later.

2. What did you expect to see?

I expect PDOPool::get() to return a working connection and check for terminated connections.

3. What did you see instead?

After some successful connections and waiting for the connection timeout to occur PDOPool::get() returns a terminated connection resulting in error 2006 MySQL server has gone away

4. What version of Swoole are you using?

Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 4.6.4
Built => Apr 8 2021 18:15:20
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

5. What is your machine environment used?

Linux 1100dd632f36 4.19.121-linuxkit #1 SMP Thu Jan 21 15:36:34 UTC 2021 x86_64 Linux

PHP 8.0.3 (cli) (built: Apr 1 2021 15:27:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies

@intellent
Copy link
Author

I’ve tried working around this issue by catching the PDOException 2006 MySQL server has gone away. How can I remove a terminated connection from PDOPool?

@sy-records
Copy link
Member

If an exception occurs, you can put null back into the pool.

try {

} catch (\Throwable $e) {
    $pool->put(null);
}

@TorstenDittmann
Copy link
Sponsor

@intellent just wanna mention how I solved this exact problem here #4131 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants