pt-kill does not report failure exit code

Bug #1314500 reported by Elan Ruusamäe
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
In Progress
Low
Frank Cizmich

Bug Description

pt-kill should exit non-zero if it failed to start the daemon:

# sudo -H -u mysql /usr/bin/pt-kill --config /etc/percona-toolkit/pt-kill.conf --daemonize --pid /var/run/percona-toolkit/pt-kill.pid --sentinel /var/run/percona-toolkit/pt-kill.sentinel
Cannot open PID file /var/run/percona-toolkit/pt-kill.pid: Permission denied at /usr/bin/pt-kill line 2401.

root@blodnatt run/percona-toolkit# echo $?
0

root@blodnatt run/percona-toolkit# pt-kill --version
pt-kill 2.2.7

Tags: pt-kill

Related branches

tags: added: pt-kill
Revision history for this message
Nilnandan Joshi (nilnandan-joshi) wrote :

Unable to reproduce with pt-kill-2.2.9, can you please install latest version and check?

nilnandan@nilnandan-Dell-XPS:~$ pt-kill --version
pt-kill 2.2.9
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ sudo -H -u mysql /usr/bin/pt-kill --config /etc/percona-toolkit/pt-kill.conf --kill-query --daemonize --pid /var/run/percona-toolkit/pt-kill.pid --sentinel /var/run/percona-toolkit/pt-kill.sentinel
DBI connect(';host=localhost;mysql_read_default_group=client','',...) failed: Access denied for user 'nilnandan'@'localhost' (using password: NO) at /usr/bin/pt-kill line 2059.
nilnandan@nilnandan-Dell-XPS:~$ echo $?
255
nilnandan@nilnandan-Dell-XPS:~$

nilnandan@nilnandan-Dell-XPS:~$ pt-kill --user=root --match-command Sleep --kill --victims all --interval 10
DBI connect(';host=localhost;mysql_read_default_group=client','root',...) failed: Access denied for user 'root'@'localhost' (using password: NO) at /usr/bin/pt-kill line 2059.
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ echo $?
255
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ pt-kill --user=root --match-command Sleep --kill --victims all --interval 10 --config /etc/percona-toolkit/pt-kill
Unknown option: config
Usage: pt-kill [OPTIONS] [DSN]

Errors in command-line arguments:
  * Error parsing options

pt-kill kills MySQL connections. pt-kill connects to MySQL and gets queries from
SHOW PROCESSLIST if no FILE is given. Else, it reads queries from one or more
FILE which contains the output of SHOW PROCESSLIST. If FILE is -, pt-kill reads
from STDIN. For more details, please use the --help option, or try 'perldoc
/usr/bin/pt-kill' for complete documentation.
nilnandan@nilnandan-Dell-XPS:~$
nilnandan@nilnandan-Dell-XPS:~$ echo $?
1
nilnandan@nilnandan-Dell-XPS:~$

Changed in percona-toolkit:
status: New → Incomplete
Revision history for this message
Frank Cizmich (frank-cizmich) wrote :

The problem is that the error is occurring within the child process (the daemon), but the exit code returned is from the parent "launcher" process.

I've coded a tentative workaround patch that makes the parent wait a second to have a chance to capture any immediate child error exit codes.

Changed in percona-toolkit:
status: Incomplete → Triaged
importance: Undecided → Low
status: Triaged → In Progress
assignee: nobody → Frank Cizmich (frank-cizmich)
Changed in percona-toolkit:
status: In Progress → Fix Committed
milestone: none → 2.2.11
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Frank: are you sure the problem exists? Nil can't reproduce it and from http://bazaar.launchpad.net/~percona-toolkit-dev/percona-toolkit/2.2/view/head:/lib/Daemon.pm#L56 it seems like problem would not exist.

Revision history for this message
Frank Cizmich (frank-cizmich) wrote :

Daniel,

The problem happens when the --daemonize option is used, and we have no permission to access to the PID file.

I reproduced it as follows (logged in as a regular user) :

> pt-kill --daemonize --busy-time 10 --kill --pid /var/run/percona-toolkit/pt-kill.pid -u xxxxx -p xxxxx
> Cannot open PID file /var/run/percona-toolkit/pt-kill.pid: No such file or directory at pt-kill line 2398.
> echo $?
> 0

After the fix the same command exits with error 1.

So, in essence, the process "successfully" forks, but child dies immediately for whatever reason. We now capture this by waiting a couple of seconds to see if it started correctly.

Changed in percona-toolkit:
status: Fix Committed → In Progress
Changed in percona-toolkit:
milestone: 2.2.11 → 2.2.12
Changed in percona-toolkit:
milestone: 2.2.12 → none
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-810

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.