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

MySQL server has gone away and reconnect for postfix relay.php #1169

Open
bilias opened this issue Feb 13, 2020 · 0 comments
Open

MySQL server has gone away and reconnect for postfix relay.php #1169

bilias opened this issue Feb 13, 2020 · 0 comments

Comments

@bilias
Copy link

bilias commented Feb 13, 2020

Hi,
I'm using EFA v4 with mailwatch 1.2.15
My DB is a galera cluster which is controlled by keepalived virtual service.

When a DB node is restarted I have error on the relay php scripts
mailwatch_milter_relay.php and mailwatch_postfix_relay.php

Feb 13 12:38:12 efa1 php: PHP Warning: mysqli::query(): MySQL server has gone away in /var/www/html/mailscanner/functions.php on line 1061
Feb 13 12:38:12 efa1 php: Warning: mysqli::query(): MySQL server has gone away in /var/www/html/mailscanner/functions.php on line 1061
Feb 13 12:38:12 efa1 php: Warning: mysqli::query(): Error reading result set's header in /var/www/html/mailscanner/functions.php on line 1061
Feb 13 12:38:12 efa1 php: Fatal error: Uncaught mysqli_sql_exception: MySQL server has gone away in /var/www/html/mailscanner/functions.php:1061
Feb 13 12:38:12 efa1 php: Stack trace:
Feb 13 12:38:12 efa1 php: #0 /var/www/html/mailscanner/functions.php(1061): mysqli->query('SELECT id from ...')
Feb 13 12:38:12 efa1 php: #1 /usr/bin/mailwatch/tools/Postfix_relay/mailwatch_milter_relay.php(75): dbquery('SELECT id from ...')
Feb 13 12:38:12 efa1 php: #2 /usr/bin/mailwatch/tools/Postfix_relay/mailwatch_milter_relay.php(97): doittail('tail -F -n0 /va...')
Feb 13 12:38:12 efa1 php: #3 {main}
Feb 13 12:38:12 efa1 php: thrown in /var/www/html/mailscanner/functions.php on line 1061
Feb 13 12:38:12 efa1 php: PHP Warning: mysqli::query(): Error reading result set's header in /var/www/html/mailscanner/functions.php on line 1061
Feb 13 12:38:12 efa1 php: tail: write error: Broken pipe
Feb 13 12:38:12 efa1 php: tail: write error
Feb 13 12:38:12 efa1 php: PHP Fatal error: Uncaught mysqli_sql_exception: MySQL server has gone away in /var/www/html/mailscanner/functions.php:1061#012Stack trace:#12#0 /var/www/html/mailscanner/functions.php(1061): mysqli->query('SELECT id from ...')#12#1 /usr/bin/mailwatch/tools/Postfix_relay/mailwatch_milter_relay.php(75): dbquery('SELECT id from ...')#12#2 /usr/bin/mailwatch/tools/Postfix_relay/mailwatch_milter_relay.php(97): doittail('tail -F -n0 /va...')#12#3 {main}#12 thrown in /var/www/html/mailscanner/functions.php on line 1061
Feb 13 12:38:12 efa1 systemd: milter_relay.service: main process exited, code=exited, status=255/n/a
Feb 13 12:38:12 efa1 systemd: Unit milter_relay.service entered failed state.

service is restarted by systemd but I don't like this.
what I've done is this on function dbquery()

`--- functions.php 2020-02-13 15:22:58.657710695 +0200
+++ /var/www/html/mailscanner/functions.php 2020-02-13 15:09:39.358239586 +0200
@@ -1046,8 +1057,15 @@
if (DEBUG && headers_sent() && preg_match('/\bselect\b/i', $sql)) {
dbquerydebug($link, $sql);
}

  • mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  • //mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  • mysqli_report(MYSQLI_REPORT_ERROR);
    $result = $link->query($sql);
  •    if ($link->errno == 2006) {
    
  •           $link = dbclose();
    
  •           sleep(5);
    
  •           $link = dbconn();
    
  •           $result = $link->query($sql);
    
  •    }
    

`
2006 error code is for "server gone away"
The sleep is to wait load balancer to catch the missing server and redirect to other hosts. Can by a tunable in conf.php

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

No branches or pull requests

2 participants