Skip to content

Commit

Permalink
Handle ErrorResponse in ping (#393)
Browse files Browse the repository at this point in the history
* Handle IdleSessionTimeoutError in blocking client reconnect
  • Loading branch information
fantix committed Nov 23, 2022
1 parent 4b8bec6 commit 8b28947
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions edgedb/blocking_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ async def raw_query(self, query_context: abstract.QueryContext):
time.monotonic() - self._protocol.last_active_timestamp
> self._ping_wait_time
):
await self._protocol._sync()
except errors.ClientConnectionError:
await self._protocol.ping()
except (errors.IdleSessionTimeoutError, errors.ClientConnectionError):
await self.connect()

return await super().raw_query(query_context)
Expand Down
21 changes: 21 additions & 0 deletions edgedb/protocol/protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,27 @@ cdef class SansIOProtocol:
else:
self.fallthrough()

async def ping(self):
cdef char mtype
self.write(WriteBuffer.new_message(SYNC_MSG).end_message())
exc = None
while True:
if not self.buffer.take_message():
await self.wait_for_message()
mtype = self.buffer.get_message_type()

if mtype == READY_FOR_COMMAND_MSG:
self.parse_sync_message()
break
elif mtype == ERROR_RESPONSE_MSG:
exc = self.parse_error_message()
self.buffer.finish_message()
break
else:
self.fallthrough()
if exc is not None:
raise exc

async def restore(self, bytes header, data_gen):
cdef:
WriteBuffer buf
Expand Down

0 comments on commit 8b28947

Please sign in to comment.