From d03aa7c41210c50a93df87aa70251f99cc7940c9 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Thu, 21 Sep 2023 16:46:32 +0300 Subject: [PATCH] Add a timeout for sql_ready waiting, exit from object processor if reached --- src/class_objectProcessor.py | 8 ++++++-- src/helper_sql.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 0d3a161a..47603700 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -6,6 +6,7 @@ processes the network objects # pylint: disable=too-many-branches,too-many-statements import hashlib import logging +import os import random import subprocess # nosec B404 import threading @@ -28,7 +29,8 @@ from addresses import ( ) from bmconfigparser import config from fallback import RIPEMD160Hash -from helper_sql import sql_ready, SqlBulkExecute, sqlExecute, sqlQuery +from helper_sql import ( + sql_ready, sql_timeout, SqlBulkExecute, sqlExecute, sqlQuery) from network import bmproto, knownnodes from network.node import Peer from tr import _translate @@ -44,7 +46,9 @@ class objectProcessor(threading.Thread): def __init__(self): threading.Thread.__init__(self, name="objectProcessor") random.seed() - sql_ready.wait() + if sql_ready.wait(sql_timeout) is False: + logger.fatal('SQL thread is not started in %s sec', sql_timeout) + os._exit(1) shared.reloadMyAddressHashes() shared.reloadBroadcastSendersForWhichImWatching() # It may be the case that the last time Bitmessage was running, diff --git a/src/helper_sql.py b/src/helper_sql.py index cba98884..8dee9e0c 100644 --- a/src/helper_sql.py +++ b/src/helper_sql.py @@ -33,6 +33,8 @@ sql_available = False sql_ready = threading.Event() """set by `.threads.sqlThread` when ready for processing (after initialization is done)""" +sql_timeout = 60 +"""timeout for waiting for sql_ready in seconds""" def sqlQuery(sql_statement, *args):