IMPALA-13230: Dump stacktrace for impala-shell when it receives SIGUSR1

It can be useful to get a stacktrace for a running impala-shell
for debugging. This uses Python 3's faulthandler to handle the
SIGUSR1, so it prints a stacktrace for all threads when it
receives SIGUSR1.

This does not implement an equivalent functionality for Python 2.
Python 2 doesn't have the faulthandler library, and hand tests
showed that sending SIGUSR1 to Python 2 impala-shell can interrupt
network calls and abort a running query.

Testing:
 - Added a test that verifies the stacktrace is printed and a
   running query succeeds.

Change-Id: If7dae2686b65a1a4f02488abadca3b3c90e48bf1
Reviewed-on: http://gerrit.cloudera.org:8080/21611
Reviewed-by: Yida Wu <wydbaggio000@gmail.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Reviewed-by: Michael Smith <michael.smith@cloudera.com>
This commit is contained in:
Joe McDonnell
2024-07-24 13:06:43 -07:00
committed by Michael Smith
parent 1823604fed
commit 2b98e5fb95
2 changed files with 26 additions and 0 deletions

View File

@@ -346,6 +346,25 @@ class TestImpalaShellInteractive(ImpalaTestSuite):
result = p.get_result()
assert "^C" in result.stderr
def test_sigusr1_stacktraces(self, vector):
if vector.get_value('strict_hs2_protocol'):
pytest.skip("Strict HS2 mode doesn't support sleep() function")
if vector.get_value('impala_shell') in ['dev', 'python2']:
pytest.skip("Python 2 doesn't support faulthandler")
command = "select sleep(5000); quit;"
p = ImpalaShell(vector)
p.send_cmd(command)
sleep(2)
os.kill(p.pid(), signal.SIGUSR1)
result = p.get_result()
# The stacktrace is printed to stderr. The main thread starts in impala_shell_main,
# so we expect that to be present.
assert "Current thread" in result.stderr, result.stderr
assert "impala_shell_main" in result.stderr, result.stderr
# The SIGUSR1 doesn't harm the running query.
assert "Fetched 1 row(s)" in result.stderr, result.stderr
assert result.rc == 0, result.stderr
@pytest.mark.execute_serially
def test_cancellation_mid_command(self, vector):
"""Test that keyboard interrupt cancels multiline query strings"""