@@ -88,6 +88,17 @@ cdef class BaseProtocol:
8888 self ._write_buf._transport = None
8989 transport.disconnect()
9090
91+ cdef bint _get_is_healthy(self ):
92+ """
93+ Returns a boolean indicating if the connection is considered healthy.
94+ """
95+ # if a read failed on the socket earlier, clear the socket
96+ if self ._read_buf._transport is None \
97+ or self ._read_buf._transport._transport is None :
98+ self ._transport = None
99+ return self ._transport is not None \
100+ and self ._read_buf._pending_error_num == 0
101+
91102 cdef int _post_connect(self , BaseThinConnImpl conn_impl,
92103 AuthMessage auth_message) except - 1 :
93104 """ "
@@ -155,15 +166,9 @@ cdef class Protocol(BaseProtocol):
155166
156167 with self ._request_lock:
157168
158- # if a read failed on the socket earlier, clear the socket
159- if self ._read_buf._transport is None \
160- or self ._read_buf._transport._transport is None :
161- self ._transport = None
162-
163169 # if the session was marked as needing to be closed, force it
164170 # closed immediately (unless it was already closed)
165- if self ._read_buf._pending_error_num != 0 \
166- and self ._transport is not None :
171+ if not self ._get_is_healthy() and self ._transport is not None :
167172 self ._force_close()
168173
169174 # rollback any open transaction and release the DRCP session, if
@@ -529,14 +534,9 @@ cdef class BaseAsyncProtocol(BaseProtocol):
529534
530535 async with self ._request_lock:
531536
532- # if a read failed on the socket earlier, clear the socket
533- if self ._read_buf._transport is None :
534- self ._transport = None
535-
536537 # if the session was marked as needing to be closed, force it
537538 # closed immediately (unless it was already closed)
538- if self ._read_buf._pending_error_num != 0 \
539- and self ._transport is not None :
539+ if not self ._get_is_healthy() and self ._transport is not None :
540540 self ._force_close()
541541
542542 # rollback any open transaction and release the DRCP session, if
0 commit comments