Skip to content

Commit 5d0786a

Browse files
committed
Fix a pointer truncation in socket liveness check
Socket liveness check ocasionally failed due to the buffer pointer truncation that was passed to libc's recv via ctypes, triggering reconnection, causing general slowdown.
1 parent 421da58 commit 5d0786a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tarantool/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ class Connection(object):
6363
Also this class provides low-level interface to data manipulation
6464
(insert/delete/update/select).
6565
'''
66-
_libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
67-
_sys_recv = ctypes.CFUNCTYPE(c_ssize_t, ctypes.c_int, ctypes.c_void_p,
68-
c_ssize_t, ctypes.c_int,
69-
use_errno=True)(_libc.recv)
70-
7166
Error = tarantool.error
7267
DatabaseError = tarantool.error.DatabaseError
7368
InterfaceError = tarantool.error.InterfaceError
@@ -90,6 +85,11 @@ def __init__(self, host, port,
9085
creates network connection.
9186
if False than you have to call connect() manualy.
9287
'''
88+
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
89+
recv = self._sys_recv = libc.recv
90+
recv.argtypes = [
91+
ctypes.c_int, ctypes.c_void_p, c_ssize_t, ctypes.c_int]
92+
recv.restype = c_ssize_t
9393
self.host = host
9494
self.port = port
9595
self.user = user

0 commit comments

Comments
 (0)