One of the die in pt-heartbeat cannot capture the error code and exit, which lead to It still try to connect even though the master stop

Bug #1629164 reported by victor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Confirmed
Undecided
Unassigned

Bug Description

pt-heartbeat 2.2.19

here is the command before i stop the mysql server
[root@localhost ~]# pt-heartbeat --update -h 192.168.244.20 -u monitor -p monitor123 -D test

the i stop the server
# service mysqld stop

then the command output this with stop
[root@localhost ~]# pt-heartbeat --update -h 192.168.244.20 -u monitor -p monitor123 -D test
MySQL server has gone away [for Statement "SHOW MASTER STATUS"]
Can't connect to MySQL server on '192.168.244.20' (111)
Can't connect to MySQL server on '192.168.244.20' (111)
Can't connect to MySQL server on '192.168.244.20' (111)
Can't connect to MySQL server on '192.168.244.20' (111)
...

i check the code
# vim /usr/local/bin/pt-heartbeat
2818 my $dbh;
2819 while ( !$dbh && $tries-- ) {
2820 PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass,
2821 join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults ));
2822
2823 $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) };
2824
2825 if ( !$dbh && $EVAL_ERROR ) {
2826 if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) {
2827 die "Cannot connect to MySQL because the Perl DBD::mysql module is "
2828 . "not installed or not found. Run 'perl -MDBD::mysql' to see "
2829 . "the directories that Perl searches for DBD::mysql. If "
2830 . "DBD::mysql is not installed, try:\n"
2831 . " Debian/Ubuntu apt-get install libdbd-mysql-perl\n"
2832 . " RHEL/CentOS yum install perl-DBD-MySQL\n"
2833 . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n";
2834 }
2835 elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) {
2836 PTDEBUG && _d('Going to try again without utf8 support');
2837 delete $defaults->{mysql_enable_utf8};
2838 }
2839 if ( !$tries ) {
2840 die $EVAL_ERROR;
2841 }
2842 }

obviously,if the connect failed two times,then the $tries would be 0,and trigger the die,then the script quit.
but in fact,it did not quit,and still reconnect,which leaded to the memory used by the script slowly increased but steadily.

then i change the code,in line 2840,like this
 die "just_test:$EVAL_ERROR";

the i repeat this test
# service mysqld start
[root@localhost ~]# pt-heartbeat --update -h 192.168.244.20 -u monitor -p monitor123 -D test

# service mysqld stop
then we can found the script quit

# pt-heartbeat --update -h 192.168.244.20 -u monitor -p monitor123 -D test
MySQL server has gone away [for Statement "SHOW MASTER STATUS"]
just_test:DBI connect('test;host=192.168.244.20;mysql_read_default_group=client','monitor',...) failed: Can't connect to MySQL server
 on '192.168.244.20' (111) at /usr/local/bin/pt-heartbeat line 2823

i believe i could be bug,and i also have a question,why the unsuccessful connection can lead to memory increase.

Thanks

Tags: pt-heartbeat
Revision history for this message
Sveta Smirnova (svetasmirnova) wrote :

Thank you for the report.

According to the documentation at "pt-heartbeat will try to reconnect if the connection has an error, but will not retry if it can’t get a connection when it first starts.", so option tries is related to startup only.

So I can verify this as feature request only: "add option, telling to stop reconnecting to master after N failed connection attempts"

Changed in percona-toolkit:
status: New → Confirmed
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-1386

Revision history for this message
Shlomi Noach (shlomi-noach) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.