-
-
Notifications
You must be signed in to change notification settings - Fork 569
Description
Hi @aaugustin
I really tried looking all over for a solution to this issue i've recently started facing and i'm hoping you could help me out.
I have the below script in a class that connects to a server and process messages from many sockets that are setup. The program needs to kill the sockets and generate new ones every timerTopics minutes:
async def wssSubscribe(self,payload):
link,data=payload
async with websockets.connect(link) as ws:
#setup subscription
await ws.send(data)
message = await ws.recv()
message = json.loads(message)
subscriptionID = message["result"]
try:
#Get & process messages
async for message in ws:
message = json.loads(message)["params"]["result"]
print(message)
self.dumpToSql(responses=message)
#On cancellation, cancel subscription
except asyncio.CancelledError:
message = self.baseProvider.encode_rpc_request(method='eth_unsubscribe', params=[subscriptionID])
await ws.send(message)
await ws.recv()
await ws.close()
#On other exception
except Exception as e:
#Inform user
print(f"Exception {e} seen while gathering topics wss")
#Triggers task regensis
self.activateTopicsHeal = True
print(traceback.format_exc())
#Unsubscribe
message = self.baseProvider.encode_rpc_request(method='eth_unsubscribe', params=[subscriptionID])
await ws.send(message)
await ws.close()
#Regenerate new tasks automatically
async def taskGenerator(self):
loop = asyncio.get_running_loop()
try:
while True:
await asyncio.sleep(60 * (self.timerTopics - 1 ))
self.tasksToKill = self.wssTasks.copy()
self.wssTasks = list()
for payload in self.payloads:
task = self.wssSubscribe(payload)
task = asyncio.ensure_future(task,loop=loop)
self.wssTasks.append(task)
await self.cancelWSSTasks(self.tasksToKill)
except asyncio.CancelledError:
print("cancellation happened!")
Now every now and then since the last 3 weeks I started getting this, showing up under general exception catch...
Traceback (most recent call last):
File "C:\kaleb\data_manager\utils\gatherTopicsWSS.py", line 60, in wssSubscribe
async for message in ws:
File "C:\kaleb\miniconda\envs\keeper\lib\site-packages\websockets\protocol.py", line 439, in __aiter__
yield await self.recv()
File "C:\kaleb\miniconda\envs\keeper\lib\site-packages\websockets\protocol.py", line 509, in recv
await self.ensure_open()
File "C:\kaleb\miniconda\envs\keeper\lib\site-packages\websockets\protocol.py", line 812, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1011 (unexpected error), reason = Internal logs subscription error
I've looked all over the web and stackoverflow and all i could find is that someone saying the ping/pong is killing my socket, tried setting it to None, the problem persists... do you think i have something deep in my script causing this that i should change...
Forgot to mention, I am on ubuntu with websocket version 8.1 the latest...
Thank you for your help 🙏🏼