jmac11 / googlecloudsql

Automatically exported from code.google.com/p/googlecloudsql
0 stars 0 forks source link

random "server has gone away" errors from GAE to cloud SQL #79

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
i'm connecting using PHP-PDO and catching PDOExceptions while connecting... it 
works 99% of the time, but still fails quite regularly and there doesn't seem 
to be a way to test for that and re-establish the connection.

Original issue reported on code.google.com by cloudward.build@gmail.com on 30 Jan 2014 at 1:07

GoogleCodeExporter commented 9 years ago
Hello,

Could you share the error message that you are getting?

Original comment by jemu...@google.com on 30 Jan 2014 at 1:11

GoogleCodeExporter commented 9 years ago
there are a bunch...

PHP Warning:  PDO::__construct(): MySQL server has gone away in /file....
PHP Warning:  PDO::__construct(): Error while reading greeting packet. PID=-1 
in /file....
PHP Warning:  PDO::exec(): MySQL server has gone away in /file...
PHP Warning:  PDO::exec(): Error reading result set's header in /file...

all on code that works correctly.   we're also seeing issues with wordpress 
installs... same thing, every once in a while you get the wordpress "Error 
establishing a database connection"

Original comment by cloudward.build@gmail.com on 30 Jan 2014 at 1:31

GoogleCodeExporter commented 9 years ago
What is the instance name? how often do you see this issue? do your logs show 
an exact date/time?

Also, have you configured your Cloud SQL instance to be located with your App 
Engine app on the settings to minimize latency and network issues?

Original comment by jemu...@google.com on 30 Jan 2014 at 1:35

GoogleCodeExporter commented 9 years ago
I've contacted you directly to your email so you can provide us extra 
information.

Original comment by jemu...@google.com on 30 Jan 2014 at 1:46

GoogleCodeExporter commented 9 years ago
the cloud SQL instance is not set to follow the app, but there is only 1 app 
that is authorized for the Cloud SQL instance, and the "Authorized App Engine 
Applications" help says "Your database will be located as close as possible to 
the first application on the list".... so we figured the other setting wasn't 
required.

also, we're setting up the DB using the PHP API client, and changing the 
"Preferred Location" of the cloud SQL instance doesn't seem to be available to 
change.

Original comment by cloudward.build@gmail.com on 30 Jan 2014 at 3:24

GoogleCodeExporter commented 9 years ago
We are still getting this issue, I responded to the email but have not heard 
back

Original comment by lu...@cloudward.com on 7 Feb 2014 at 4:04

GoogleCodeExporter commented 9 years ago
I'm actually hitting the same issue.

I've wrote a class which extends the PDO class, in the constructor I create a 
new pdo connection then set it to an internal public variable.

I then attempt to run a query but receive this error: SQLSTATE[HY000] [2006] 
MySQL server has gone away

I have attempted to increase the max_allowed_packet along with a bunch of other 
dead ends.

<?php

class Database extends PDO
{

    public $pdo     = null;

    public function __construct( $dbType, $dbHost, $dbName, $dbUser, $dbPass, $dbAppId, $dbInstance )
    {
        try {
            //try a database connection...
            if ( strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'development') !== FALSE ) {
                $this->pdo = new pdo( $dbType . ':host=' . $dbHost . ':3306;dbname=' . $dbName, $dbUser, $dbPass );
            } else {
                $this->pdo = new pdo('mysql:unix_socket=/cloudsql/' . $dbAppId . ':' . $dbInstance . ';dbname=' . $dbName, 'root', '');
            }

            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
            $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        } catch (PDOException $e) {
            syslog( LOG_ERR, $e->getMessage() . ' - ' . __FILE__ . ' - ' . __LINE__ );
        }
    }

}

?>

<?php

$db = new Database(CMS_DB_TYPE, CMS_DB_HOST, CMS_DB_NAME, CMS_DB_USER, 
CMS_DB_PASS, CMS_DB_APP_ID, CMS_DB_INSTANCE);

$stmt = $db->pdo->prepare("SELECT * FROM `XYZ`;");
$stmt->execute(array(
    ':username' => 'bob'
));

?>

Original comment by sav...@verostudios.com on 12 Jul 2014 at 1:59

GoogleCodeExporter commented 9 years ago
I am getting the same error did anybody figure this out?

Original comment by eugin...@gmail.com on 4 Sep 2014 at 7:11

GoogleCodeExporter commented 9 years ago
The google app engine documentation states:

"Google Cloud Platform project called <your-project-id> is connecting to a 
Cloud SQL instance named <your-instance-name>."

You're probably getting an error because for project id you are using the 
project Id for your appengine application, not your Cloud SQL project ID.

Try:

$db = new 
pdo('mysql:unix_socket=/cloudsql/<sql-project-id>:<sql-instance-name>;dbname=<db
-name>', 'root', '');

Original comment by eugin...@gmail.com on 4 Sep 2014 at 8:18

GoogleCodeExporter commented 9 years ago
Yes,

This error is thrown due to not having permissions to connect. One thing I 
learned, make sure to put the correct app engine id in if you connecting from 
app, your IP if you connecting remotely or the compute engine IP.

to find out your IP type "what is my ip" in google search.

Original comment by sav...@verostudios.com on 4 Sep 2014 at 2:51

GoogleCodeExporter commented 9 years ago
My experience has nothing to do with the permissions being correct. I had an 
app that had been running for several months that started giving this error 
occasionally. 

It's not, say, 1 in a million requests or anything like that. It's more like 
when it starts happening, it'll happen on all requests for a few minutes, then 
go away. As the OP said, there doesn't appear to be any good way to test for 
it, so it just leads to a general failure. 

I switched the Cloud SQL settings to "Always On" from "On Demand." While that 
shouldn't be the cause, given that I would see the error happen within seconds 
of a successful request, I figured it couldn't hurt. It's too early to tell.

Original comment by kf6nvr on 4 Sep 2014 at 3:06

GoogleCodeExporter commented 9 years ago
We're getting this very same problem on an app that works perfectly fine for 
100 concurrent users, then once it bumps up a bit in traffic we get these:

PHP Warning: PDO::__construct(): MySQL server has gone away in db.php
PHP Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in 
db.php

and these:

PHP Warning: PDO::__construct(): MySQL server has gone away in db.php
PHP Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in 
db.php
PHP Warning: PDO::__construct(): MySQL server has gone away in db.php
PHP Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in 
db.php
PHP Fatal error: Uncaught exception 'MissingConnectionException' with message 
'Database connection "Mysql" is missing, or could not be created.' in /

Anybody had success with solving this?

kf6nvr, did you get it fixed?

Original comment by em...@mathewjohnson.com on 30 Sep 2014 at 11:23

GoogleCodeExporter commented 9 years ago
Same issue here. Happens rarely and randomly.

Original comment by anto...@thirdshelf.com on 6 Oct 2014 at 4:31

GoogleCodeExporter commented 9 years ago
@12: Although I haven't seen it lately, I can't prove it's fixed because of how 
rare and random it is. 

Original comment by kf6nvr on 6 Oct 2014 at 4:33

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
it's random problem, I got this in my GAE app log showing it happen 
occasionally.

Original comment by lawre...@webunion.com on 14 Nov 2014 at 6:32

GoogleCodeExporter commented 9 years ago
set  max_allowed_packet=200m in my.ini through htaccess

Original comment by ambikesh...@gmail.com on 14 Nov 2014 at 12:29

GoogleCodeExporter commented 9 years ago
I got the same bug:

$db = new 
pdo('mysql:unix_socket=/cloudsql/leafy-summer-854:db;dbname=guestbook',
  'root',
  '******'
);
var_dump($db);

Warning: PDO::__construct(): MySQL server has gone away in 
/base/data/home/apps/s~leafy-summer-854/1.382271048388543148/cloudsql.php on 
line 33 Warning: PDO::__construct(): Error while reading greeting packet. 
PID=-1 in 
/base/data/home/apps/s~leafy-summer-854/1.382271048388543148/cloudsql.php on 
line 33 Fatal error: Uncaught exception 'PDOException' with message 
'SQLSTATE[HY000] [2006] MySQL server has gone away' in 
/base/data/home/apps/s~leafy-summer-854/1.382271048388543148/cloudsql.php:33 
Stack trace: #0 
/base/data/home/apps/s~leafy-summer-854/1.382271048388543148/cloudsql.php(33): 
PDO->__construct('mysql:unix_sock...', 'root', 'root') #1 {main} thrown in 
/base/data/home/apps/s~leafy-summer-854/1.382271048388543148/cloudsql.php on 
line 33

Original comment by pengyu...@gmail.com on 16 Feb 2015 at 7:54

GoogleCodeExporter commented 9 years ago
This issue also happens to our project.  The sql works fine most of the time, 
but occasionally we get the error that MYSQL has gone away for every request 
and after about 5-30 minutes it comes back.  This is hugely detrimental to our 
product that relies on 24/7 services.

Any updates??

Original comment by tcsil...@gmail.com on 2 May 2015 at 6:43