@@ -88,6 +88,17 @@ cdef class BaseProtocol:
88
88
self ._write_buf._transport = None
89
89
transport.disconnect()
90
90
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
+
91
102
cdef int _post_connect(self , BaseThinConnImpl conn_impl,
92
103
AuthMessage auth_message) except - 1 :
93
104
""" "
@@ -155,15 +166,9 @@ cdef class Protocol(BaseProtocol):
155
166
156
167
with self ._request_lock:
157
168
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
-
163
169
# if the session was marked as needing to be closed, force it
164
170
# 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 :
167
172
self ._force_close()
168
173
169
174
# rollback any open transaction and release the DRCP session, if
@@ -529,14 +534,9 @@ cdef class BaseAsyncProtocol(BaseProtocol):
529
534
530
535
async with self ._request_lock:
531
536
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
-
536
537
# if the session was marked as needing to be closed, force it
537
538
# 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 :
540
540
self ._force_close()
541
541
542
542
# rollback any open transaction and release the DRCP session, if
0 commit comments