@@ -16,9 +16,11 @@ class WebsocketConnection(Connection):
16
16
async def connect (self ):
17
17
try :
18
18
self ._ws = await connect (
19
- self ._base_url + "/rpc" , subprotocols = [Subprotocol ("cbor" )]
19
+ self ._base_url + "/rpc" ,
20
+ subprotocols = [Subprotocol ("cbor" )],
21
+ max_size = 1048576 ,
20
22
)
21
- self ._receiver_task = asyncio .create_task (self .listen_to_ws (self ._ws ))
23
+ self ._receiver_task = asyncio .create_task (self ._listen_to_ws (self ._ws ))
22
24
except Exception as e :
23
25
raise SurrealDbConnectionError ("cannot connect db server" , e )
24
26
@@ -48,7 +50,7 @@ async def unset(self, key: str):
48
50
await self .send (METHOD_UNSET , key )
49
51
50
52
async def close (self ):
51
- if self ._receiver_task :
53
+ if self ._receiver_task and not self . _receiver_task . cancelled () :
52
54
self ._receiver_task .cancel ()
53
55
54
56
if self ._ws :
@@ -88,7 +90,7 @@ async def _make_request(self, request_data: RequestData):
88
90
finally :
89
91
self .remove_response_queue (ResponseType .SEND , request_data .id )
90
92
91
- async def listen_to_ws (self , ws ):
93
+ async def _listen_to_ws (self , ws ):
92
94
async for message in ws :
93
95
try :
94
96
response_data = self ._decoder (message )
@@ -106,7 +108,8 @@ async def listen_to_ws(self, ws):
106
108
continue
107
109
await queue .put (response_data .get ("result" ))
108
110
except asyncio .CancelledError :
111
+ self ._logger .info ("Task cancelled. Stopped listening for RPC responses" )
109
112
break
110
- except Exception :
111
- break
112
- asyncio . get_event_loop (). stop ()
113
+ except Exception as e :
114
+ self . _logger . error ( e )
115
+ continue
0 commit comments