Skip to content

Commit

Permalink
Job timeout doesn't kill the mysql query (#4629)
Browse files Browse the repository at this point in the history
* forward timeout SIGALRMs to MySQL threads in order to kill any running proccesses

* no need to attach to SIGALRM as RQ already does that
  • Loading branch information
Omer Lachish authored Feb 24, 2020
1 parent cdfa102 commit 35250d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions redash/query_runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion redash/tasks/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 35250d6

Please sign in to comment.