Add a timeout for sql_ready waiting, exit from object processor if reached

This commit is contained in:
Lee Miller 2023-09-21 16:46:32 +03:00
parent e4488ba370
commit d03aa7c412
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 8 additions and 2 deletions

View File

@ -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,

View File

@ -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):