Skip to content

Commit ea169ff

Browse files
committed
BUG#34950958: MySQL Python Connector doesn't work with ssh in the same process
BUG#34844347: Freezes on connection via sshtunnel This patch fixes the issue where Connector/Python C-Extension does not work with sshtunnel in the same process by adding missing mechanism in the c-api codebase to release GIL while communicating with the MySQL server. Change-Id: I62b1ed87abb875eda6520ea7ac1199c0346ce0c4
1 parent 92e52d4 commit ea169ff

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ v9.4.0
1212
======
1313

1414
- BUG#37806057: Rename extra option (when installing wheel package) to install webauthn functionality dependencies
15+
- BUG#34950958: MySQL Python Connector doesn't work with ssh in the same process
16+
- BUG#34844347: Freezes on connection via sshtunnel
1517

1618
v9.3.0
1719
======

mysql-connector-python/src/mysql_capi.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,9 @@ MySQL_autocommit(MySQL *self, PyObject *mode)
815815

816816
if (Py_TYPE(mode) == &PyBool_Type) {
817817
new_mode = (mode == Py_True) ? 1 : 0;
818-
818+
Py_BEGIN_ALLOW_THREADS
819819
res = (int)mysql_autocommit(&self->session, new_mode);
820+
Py_END_ALLOW_THREADS
820821
if (res == -1 && mysql_errno(&self->session)) {
821822
raise_with_session(&self->session, NULL);
822823
return NULL;
@@ -1090,7 +1091,9 @@ MySQL_commit(MySQL *self)
10901091

10911092
IS_CONNECTED(self);
10921093

1094+
Py_BEGIN_ALLOW_THREADS
10931095
res = mysql_commit(&self->session);
1096+
Py_END_ALLOW_THREADS
10941097
if (res) {
10951098
raise_with_session(&self->session, NULL);
10961099
return NULL;
@@ -1202,12 +1205,8 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds)
12021205
return NULL;
12031206
}
12041207

1208+
MySQL_close(self);
12051209
Py_BEGIN_ALLOW_THREADS
1206-
if (self->connected) {
1207-
self->connected = 0;
1208-
mysql_close(&self->session);
1209-
}
1210-
12111210
mysql_init(&self->session);
12121211
Py_END_ALLOW_THREADS
12131212

@@ -1941,7 +1940,9 @@ MySQL_ping(MySQL *self)
19411940
Py_RETURN_FALSE;
19421941
}
19431942

1943+
Py_BEGIN_ALLOW_THREADS
19441944
res = mysql_ping(&self->session);
1945+
Py_END_ALLOW_THREADS
19451946

19461947
if (!res) {
19471948
Py_RETURN_TRUE;
@@ -2993,9 +2994,11 @@ MySQL_refresh(MySQL *self, PyObject *args)
29932994

29942995
for (int i = 0; i < refresh_options_len; i++) {
29952996
if (options & refresh_options[i].option) {
2997+
Py_BEGIN_ALLOW_THREADS
29962998
res = mysql_real_query(&self->session,
29972999
refresh_options[i].statement,
29983000
strlen(refresh_options[i].statement));
3001+
Py_END_ALLOW_THREADS
29993002
if (res) {
30003003
break; /* stop processing if an error occurs */
30013004
}
@@ -3030,7 +3033,9 @@ MySQL_reset_connection(MySQL *self)
30303033
Py_RETURN_FALSE;
30313034
}
30323035

3036+
Py_BEGIN_ALLOW_THREADS
30333037
res = mysql_reset_connection(&self->session);
3038+
Py_END_ALLOW_THREADS
30343039

30353040
if (!res) {
30363041
Py_RETURN_TRUE;

0 commit comments

Comments
 (0)