11from settings import logger , cfg
22from helpers import strip_url , generate_labels_from_metadata , hex_to_int , key_from_json_str
33from metrics_processor import results
4-
54from collectors .ws import subscription , fetch_latency
5+ import json
66import websockets
77import asyncio
8- import json
98
109
1110class evm_collector ():
@@ -23,13 +22,13 @@ def __init__(self, rpc_metadata):
2322 async def _web3_clientVersion (self , websocket ):
2423 payload = {"jsonrpc" : "2.0" , "method" : "web3_clientVersion" , "params" : [], "id" : self .chain_id }
2524 await websocket .send (json .dumps (payload ))
26- result = await websocket .recv ()
25+ result = await asyncio . wait_for ( websocket .recv (), timeout = cfg . response_timeout )
2726 return key_from_json_str (result , "result" )
2827
2928 async def _eth_blockNumber (self , websocket ):
3029 payload = {"jsonrpc" : "2.0" , "method" : "eth_blockNumber" , "params" : [], "id" : self .chain_id }
3130 await websocket .send (json .dumps (payload ))
32- result = await websocket .recv ()
31+ result = await asyncio . wait_for ( websocket .recv (), timeout = cfg . response_timeout )
3332 return hex_to_int (key_from_json_str (result , "result" ))
3433
3534 async def _probe (self ) -> results :
@@ -49,7 +48,7 @@ async def _probe(self) -> results:
4948 results .record_disconnects (self .url , self .sub .disconnects )
5049 except asyncio .exceptions .TimeoutError :
5150 logger .error (
52- f"Timed out while trying to establish websocket connection. Current open_timeout value in config: { cfg .open_timeout } ." ,
51+ f"Timed out while trying to establish websocket connection. Current response_timeout value in config: { cfg .response_timeout } ." ,
5352 url = self .stripped_url )
5453 results .record_health (self .url , False )
5554 except Exception as exc :
0 commit comments