Jump to content

Recommended Posts

Posted (edited)

Hi all,

Hoping someone has experienced this before.  Honestly, I'm not sure the issue is PW specific - I'm able to login to the admin - but when I navigate to any front-end page, I get a timeout and the 'MySQL server has gone away' error message in the log.

Any help would be GREATLY appreciated.

Thanks.

Edited by horst
changed title because the initial issue isn't urgent anymore (URGENT issue - 'MySQL server has gone away' on live site)
Posted

Only thing I can think of is maybe mySQL has crashed - I suggest restarting that.

Posted

There are lot's of things to try on link Adam provided. I would assume it is something gone bad on mysql update, server restart or something like that.

Posted

Thanks guys, for the help.  I thought it was MySQL as well, but it's turning out to be an issue with RSS: a feed that we're loading through the PW RSS module is not loading - not timing out - just never loading.

Looking into the fix now, but at least I've just been able to disable that feed and get the site back up.

Posted

Ah, we had the same issue just few days ago. Still thinking about best fix. It does need some kind of background pull method and serving only from cache.

It was nasty one to debug because nothing came to logs. We just got site halting, but no mysql errors of any kind.

  • 10 months later...
Posted

I am also getting an error when I need to do a cronjob say around 16000 pages.

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

I want to check when a db connection failed whether the connection can be automatically connected again.

  • 2 weeks later...
Posted

16k pages is a lot to deal with one one request (if you are using the API as opposed to hitting the DB directly). It looks like MySQL has some resource limiter placed upon it in your case, so re-connecting probably won't help you (though that's a guess). You probably need to reduce the quantity of pages you are working with there, perhaps setting a limit (5000?) and keeping to it for each run. But if you want to check for a DB failure, your best bet is to wrap your operations in a try/catch. But I think the solution here will involve reducing the amount you do in a single cron run. 

  • 1 month later...
Posted

@horst you are welcome :-) .

Hope all is well at your end also.

Yes it is working well. I have a site on a shared host where I have got sometimes this "2006 Server has gone away" error, especially when the client was working in the admin with large pagelists (he wants to have the default limit of 50 increased to 200). But this wasn't the only time when this happens.

Now after update it with your patch I think we have to wait a week or two to be really sure it is solved. But actually I think yes it will be!

  • Like 1
  • 4 months later...
Posted

@horst, so how is things working . I was forced to fix with a different fix again . It was in `DatabaseQuery` execute method.

    public function execute() {
        try {
            $database = $this->wire('database');
            $query = $database->prepare($this->getQuery());
            $query->execute();
        } catch (Exception $e) {
            $msg = $e->getMessage();
            if (strstr($msg, 'MySQL server has gone away')) {
                $database->closePdo();
            }
            throw new Exception($e->getMessage());
        }
        return $query;
    }

and in the `WireDatabasePdo` adding a new method

    public function closePdo()
    {
        $this->pdo = null;
    }

Hope this fix will help everyone .
 

One still problem is one query can be missed which got the failure. To execute that I think it is good to call `execute()` again with some flag set.

Your thoughts ?

  • Like 2
Posted

@Hari KT: In the whole time since your first patch (5 month until now), it occured max 2 or 3 times, not more, but also not zero.

Thanks for sharing your code!

  • Like 1
Posted

@horst good to hear.

I have another patch which will more more awesome then . Don't forget to add `private static $mysql_gone = false;` in the `wire/core/DatabaseQuery.php`. And the execute changes to

public function execute() {
    try {
        $database = $this->wire('database');
        $query = $database->prepare($this->getQuery());
        $result = $query->execute();
        if (self::$mysql_gone) {
            self::$mysql_gone = false;
        }
    } catch (Exception $e) {
        if (self::$mysql_gone) {
            throw new Exception("It is better to exit than throwing error " . $e->getMessage());
        } else {
            // try once again                
            $msg = $e->getMessage();
            if (strstr($msg, 'MySQL server has gone away')) {
                self::$mysql_gone = true;
                $database->closePdo();
                sleep(20);
                $this->execute();
            } else {
                throw new Exception($e->getMessage());
            }
        }
    }
    return $query;
}

Discussion on github https://github.com/ryancramerdesign/ProcessWire/pull/563#issuecomment-50871518

  • Like 1
  • 5 months later...
Posted

Old issue I know, but I seem to be having some quirks with my current setup. I have been getting this error when I go to update a cache-field with a large amount of fields. Is this error just in reference to a timeout from my mySQL server?

  • 4 months later...
Posted

having the same issue: processwire Error: Exception: SQLSTATE[HY000]:

this is happening when I upload an image on an edit page. anyone able to shed any light?

  • 8 months later...
Posted

I get these in OVH shared hosting. Updated PHP from 5.6 to 7, but it didn't help (well, it really seems to be about the db itself..)

Error:
Exception: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away (in /home/user/www/wire/core/Pages.php line 2103)

#0 /home/user/www/wire/core/Pages.php(2103): PDOStatement->execute()
#1 /home/user/www/wire/core/Pages.php(546): Pages->executeQuery(Object(PDOStatement))
#2 /home/user/www/wire/core/PagesType.php(260): Pages->getById(Array, Object(Template))
#3 /home/user/www/wire/core/Users.php(33): PagesType->get(41)
#4 /home/user/www/wire/core/Session.php(102): Users->get(41)
#5 /home/user/www/wire/core/ProcessWire.php(279): Session->__construct()
#6 /home/user/www/wire/core/ProcessWire.php(94): ProcessWire->load(Object(Config))
#7 /home/user/www/index.php(232): ProcessWire->__construct(Object(Config))
#8 {main}

I get this even when trying to access the front page which doesn't have much else than the navigation menu. Menu is done using this: https://processwire.com/talk/topic/10448-css-only-responsive-multi-level-menu/

Root has 4 children. One of them has 9 children and each of those 3 grandchildren and some of the grandchildren have children of their own. Could walking this structure really bring the DB down?

Is there anything I can do except switch to dedicated hosting (cheapest Kimsufi is only 6 euros per month)?

According to OVH support, the MySQL variable max_allowed_packet is probably 1M and it cannot be raised.

Edit: here is the other type of message I get:

Exception: SQLSTATE[42000] [1203] User user already has more than 'max_user_connections' active connections (in /home/user/www/wire/core/ProcessWire.php line 216)

#0 /home/user/www/wire/core/ProcessWire.php(94): ProcessWire->load(Object(Config))
#1 /home/user/www/index.php(232): ProcessWire->__construct(Object(Config))
#2 {main}

I might get over 200 error emails in one go.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...