From 35250d64b9387daeb33f55b7cfb81939953c22b1 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Tue, 25 Feb 2020 00:16:19 +0200 Subject: [PATCH] Job timeout doesn't kill the mysql query (#4629) * forward timeout SIGALRMs to MySQL threads in order to kill any running proccesses * no need to attach to SIGALRM as RQ already does that --- redash/query_runner/mysql.py | 7 +++++++ redash/tasks/worker.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/redash/query_runner/mysql.py b/redash/query_runner/mysql.py index 05552eef7f..82f19394cf 100644 --- a/redash/query_runner/mysql.py +++ b/redash/query_runner/mysql.py @@ -14,6 +14,7 @@ ) from redash.settings import parse_boolean from redash.utils import json_dumps, json_loads +from redash.tasks.worker import JobTimeoutException try: import MySQLdb @@ -150,11 +151,13 @@ def _get_tables(self, schema): return list(schema.values()) + def run_query(self, query, user): ev = threading.Event() thread_id = "" r = Result() t = None + try: connection = self._connection() thread_id = connection.thread_id() @@ -164,6 +167,10 @@ def run_query(self, query, user): t.start() while not ev.wait(1): pass + except JobTimeoutException as e: + self._cancel(thread_id) + t.join() + raise e except (KeyboardInterrupt, InterruptException): error = self._cancel(thread_id) t.join() diff --git a/redash/tasks/worker.py b/redash/tasks/worker.py index 3f68351228..c74983afce 100644 --- a/redash/tasks/worker.py +++ b/redash/tasks/worker.py @@ -4,7 +4,7 @@ import time from rq import Worker as BaseWorker, Queue as BaseQueue, get_current_job from rq.utils import utcnow -from rq.timeouts import UnixSignalDeathPenalty, HorseMonitorTimeoutException +from rq.timeouts import UnixSignalDeathPenalty, HorseMonitorTimeoutException, JobTimeoutException from rq.job import Job as BaseJob, JobStatus