Laravel-swoole: when i start swoole for a few days , it return error with mysql connect , laravel return "message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

Created on 13 Dec 2019  路  5Comments  路  Source: swooletw/laravel-swoole

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks!
(Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
    php version: 7.3.10
    swoole version: 4.4.12

  2. Please provide your Laravel/Lumen version.

laravel version: 6.5.2

  1. Which release version of this package are you using?
    "swooletw/laravel-swoole": "^2.6",

  2. What did you do? If possible, provide a recipe for reproducing the error.
    when i start swoole for a few days , it return error with mysql connect , laravel return "message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away, and i need to run php artisan swoole:http reload then it's ok .

  3. What did you expect to see?

  4. What did you see instead?

help wanted

Most helpful comment

@HenkPoley to be sure, Laravel it does:

@JamesKid can you reproduce your issue with these steps?

  1. Set swoole workers count to 1 (config/swoole_http.php, 'worker_num')
  2. Run HTTP request when your app is connected to MySQL
  3. Stop MySQL server and run HTTP request again, you should get MySQL server has gone away
  4. Start MySQL server and run HTTP request again, it should be fine now

All 5 comments

From other long running servers that use MySQL, this usually means a new MySQL connection needs to be set up. Often the object that you use to connect with the database has boolean which states that the last query had a problem, then the next query will re-connect.

I'm not sure if Laravel(-swoole) would do any of that, if you would just retry the query (DB::transaction() can do automatic retries).

@HenkPoley to be sure, Laravel it does:

@JamesKid can you reproduce your issue with these steps?

  1. Set swoole workers count to 1 (config/swoole_http.php, 'worker_num')
  2. Run HTTP request when your app is connected to MySQL
  3. Stop MySQL server and run HTTP request again, you should get MySQL server has gone away
  4. Start MySQL server and run HTTP request again, it should be fine now

Yes锛孖 HAVE the same question
The following detail is from Laravel's schedule in every minute.

PDOStatement::execute(): MySQL server has gone away (SQL: select * from `xxxx` where `freeze_end_time` < 2020-05-04 16:02:00 and `status` = 0 and `xxxx`.`delete_time` is null order by `id` asc limit 100 offset 0 for update)

This MySQL instance is used by other project锛宎nd running in good state.

PHP 7.2.19 (cli) (built: Jul 31 2019 17:32:32) ( NTS )

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.4.8
Built => Oct 21 2019 16:43:48
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
http2 => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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

laravel version: 5.8.35
swooletw/laravel-swoole  v2.6.66
CentOS 7

any workarounds for this?

Unable to reproduce here as well

Was this page helpful?
0 / 5 - 0 ratings

Related issues

storyn26383 picture storyn26383  路  5Comments

omsun123 picture omsun123  路  6Comments

caveman74 picture caveman74  路  7Comments

codercms picture codercms  路  5Comments

jiangjiang0228 picture jiangjiang0228  路  8Comments