Skip to content

Commit 175ed2a

Browse files
Fixed handling of errors that take place during the initial socket
creation with multiple addresses/descriptions in the connect string or with retry_count > 0.
1 parent bf78547 commit 175ed2a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/oracledb/impl/thin/connection.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ cdef class ThinConnImpl(BaseConnImpl):
6666
uint32_t _call_timeout
6767
str _cclass
6868

69+
def __init__(self, str dsn, ConnectParamsImpl params):
70+
BaseConnImpl.__init__(self, dsn, params)
71+
self._protocol = Protocol()
72+
6973
cdef int _add_cursor_to_close(self, Statement stmt) except -1:
7074
if self._num_cursors_to_close == TNS_MAX_CURSORS_TO_CLOSE:
7175
raise Exception("too many cursors to close!")
@@ -224,7 +228,7 @@ cdef class ThinConnImpl(BaseConnImpl):
224228
self._drcp_enabled = description.server_type == "pooled"
225229
if self._cclass is None:
226230
self._cclass = description.cclass
227-
self._protocol = Protocol(sock)
231+
self._protocol._set_socket(sock)
228232
redirect_params = self._protocol._connect_phase_one(self, params,
229233
description,
230234
address)

src/oracledb/impl/thin/protocol.pyx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ cdef class Protocol:
4242
bint _txn_in_progress
4343
bint _break_in_progress
4444

45-
def __init__(self, sock):
45+
def __init__(self):
4646
self._caps = Capabilities()
47-
self.__set_socket(sock)
47+
# mark protocol to indicate that connect is in progress; this prevents
48+
# the normal break/reset mechanism from firing, which is unnecessary
49+
# since the connection is going to be immediately closed anyway!
50+
self._in_connect = True
4851
self._request_lock = threading.RLock()
4952

50-
cdef int __set_socket(self, sock):
51-
self._socket = sock
52-
self._read_buf = ReadBuffer(sock, TNS_SDU, self._caps)
53-
self._write_buf = WriteBuffer(sock, TNS_SDU, self._caps)
54-
5553
cdef int _break_external(self) except -1:
5654
"""
5755
Method for sending a break to the server from an external request. A
@@ -133,11 +131,6 @@ cdef class Protocol:
133131
uint8_t packet_type
134132
str connect_string
135133

136-
# mark protocol to indicate that connect is in progress; this prevents
137-
# the normal break/reset mechanism from firing, which is unnecessary
138-
# since the connection is going to be immediately closed anyway!
139-
self._in_connect = True
140-
141134
# store whether OOB processing is possible or not
142135
self._caps.supports_oob = not params.disable_oob \
143136
and sys.platform != "win32"
@@ -175,7 +168,7 @@ cdef class Protocol:
175168
ssl_context.check_hostname = False
176169
sock = socket.socket(fileno=self._socket.detach())
177170
sock = ssl_context.wrap_socket(sock)
178-
self.__set_socket(sock)
171+
self._set_socket(sock)
179172

180173
cdef int _connect_phase_two(self, ThinConnImpl conn_impl,
181174
Description description,
@@ -370,3 +363,8 @@ cdef class Protocol:
370363
buf.write_uint8(0)
371364
buf.write_uint8(marker_type)
372365
buf.end_request()
366+
367+
cdef int _set_socket(self, sock):
368+
self._socket = sock
369+
self._read_buf = ReadBuffer(sock, TNS_SDU, self._caps)
370+
self._write_buf = WriteBuffer(sock, TNS_SDU, self._caps)

0 commit comments

Comments
 (0)