diff --git a/zerver/lib/timeout.py b/zerver/lib/timeout.py index c85d73cc1f..46ef82c083 100644 --- a/zerver/lib/timeout.py +++ b/zerver/lib/timeout.py @@ -1,4 +1,5 @@ import ctypes +import logging import sys import threading import time @@ -82,6 +83,12 @@ def timeout(timeout: float, func: Callable[[], ResultT]) -> ResultT: # Re-raise the exception we sent, if possible, so the # stacktrace originates in the slow code raise thread.exc_info[1].with_traceback(thread.exc_info[2]) + # If we don't have that for some reason (e.g. we failed to + # kill it), just raise from here; the thread _may still be + # running_ because it failed to see any of our exceptions, and + # we just ignore it. + if thread.is_alive(): + logging.warning("Failed to time out backend thread") raise TimeoutExpired if thread.exc_info[1] is not None: