improved connection error and termination handling

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-03-31 09:25:12 +02:00
parent 4837522570
commit b2c5a5297a
No known key found for this signature in database
3 changed files with 29 additions and 12 deletions

View File

@ -69,5 +69,12 @@ class ABCI_RPC:
"params": [encode_transaction(tx_dict)],
"id": str(uuid4()),
}
# TODO: handle connection errors!
return requests.post(endpoint, json=payload)
try:
response = requests.post(endpoint, json=payload)
except requests.exceptions.ConnectionError as e:
logger.error(f"Tendermint RCP Connection issue: {e}")
raise e
except Exception as e:
logger.error(f"Tendermint RCP Connection issue: {e}")
raise e
return response

View File

@ -1,9 +1,11 @@
from queue import Empty
from collections import defaultdict
import multiprocessing
import logging
from planetmint.ipc.events import EventTypes, POISON_PILL
logger = logging.getLogger(__name__)
class Exchange:
"""Dispatch events to subscribers."""
@ -63,10 +65,13 @@ class Exchange:
def run(self):
"""Start the exchange"""
self.started_queue.put("STARTED")
while True:
event = self.publisher_queue.get()
if event == POISON_PILL:
return
else:
self.dispatch(event)
try:
while True:
event = self.publisher_queue.get()
if event == POISON_PILL:
return
else:
self.dispatch(event)
except Exception as e:
logger.debug(f"Exchange Exception: {e}")

View File

@ -104,9 +104,14 @@ class TransactionListApi(Resource):
but this node only accepts transaction with higher \
schema version number.",
)
status_code, message = ABCI_RPC().write_transaction(
MODE_LIST, ABCI_RPC().tendermint_rpc_endpoint, MODE_COMMIT, tx_obj, mode
)
try:
status_code, message = ABCI_RPC().write_transaction(
MODE_LIST, ABCI_RPC().tendermint_rpc_endpoint, MODE_COMMIT, tx_obj, mode
)
except Exception as e:
logger.error(f"Tendermint RPC connection issue: {e}")
status_code = 500
message = { "detail": "Tendermint RPC connection error"}
if status_code == 202:
response = jsonify(tx)