0
votes

I have a GCE instance that has been running a PHP app for several months. I also have a Cloud SQL instance that has been running MySQL for several months, that is used by the PHP app running on GCE. Both have IPv4 addresses assigned and the Cloud SQL instance specifically has the IP from the GCE instance allowed for access.

For the most part, things work fine, but throughout the day, I get these errors at random times:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

I am not able to find a pattern, but it happens dozens of times throughout the day. According to Cloud SQL documentation, this is most likely due to the source IP not being authorized - however, it clearly is as things generally work, except for the times they don't.

I can't find anything wrong with my configuration - if I use a local MySQL instance (on the GCE instance), things work fine, but I would like to be using Cloud SQL for a variety of reasons.

Any tips or assistance would be appreciated.

EDIT: I should probably note that my entire stack is PHP 5.4.16, Nginx/PHP-FPM/Xenforo, running on GCE, connecting to Cloud SQL.

EDIT2: Digging around, I find these errors that seem related:

[3230745.933113] php-fpm[1070]: segfault at 451 ip 00007f464ee06ecc sp 00007fff3d94fdf0 error 4
[3230745.936218] php-fpm[2386]: segfault at 451 ip 00007f464ee06ecc sp 00007fff3d94fdf0 error 4
[3230745.936222]  in libmysqlclient.so.18.0.0[7f464edd5000+28c000]

[3230745.939295] php-fpm[2379]: segfault at 451 ip 00007f464ee06ecc sp 00007fff3d94fdf0 error 4
[3230745.939298]  in libmysqlclient.so.18.0.0[7f464edd5000+28c000]

[3230745.940917] php-fpm[2389]: segfault at 451 ip 00007f464ee06ecc sp 00007fff3d950120 error 4
[3230745.940920]  in libmysqlclient.so.18.0.0[7f464edd5000+28c000]

[3230746.002919]  in libmysqlclient.so.18.0.0[7f464edd5000+28c000]
1
Which PHP library are you using to connect to the DB? Are you using persistent connections?Vadim
It appears that I have both mysql and mysqli enabled, though only mysqli shows an active link (via phpinfo). Both are 5.5.46.jaychris
Do you have mysqli.allow_persistent enabled in php.ini? Can you show some example code you use to connect and perform a query?Vadim

1 Answers

0
votes

Are you using SSL to connect to your instance?

When the connection fails as described, do you do some kind of exponential backoff before attempting to reconnect?