Bug #115788 Option `connection_timeout` is overwritten and works as "query" timeout instead
| Submitted: | 6 Aug 2024 19:27 | Modified: | 8 Jan 2025 21:57 |
|---|---|---|---|
| Reporter: | Oscar Pacheco | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / Python | Severity: | S2 (Serious) |
| Version: | 8.4.0 | OS: | Any |
| Assigned to: | CPU Architecture: | Any |
[6 Aug 2024 19:27]
Oscar Pacheco
[19 Aug 2024 21:23]
Oscar Pacheco
There is an acceptable workaround for the pure-python implementation to control a query timeout. For instance, while using the "non-async" connector, you could access the protected attribute `socket` and set the wanted timeout, which will impact directly on the queries' timeout.
```
>>> cnx = mysql.connector.connec(**config)
>>> cnx._socket.set_connection_timeout(1)
>>> cnx.query('SELECT SLEEP(10);') # creates a cursor and executes the query
...
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at '127.0.0.1:7306', system error: The read operation timed out
```
Regards.
[19 Aug 2024 21:29]
Oscar Pacheco
Improving the snippet, it should be:
```
config - {...} # connection options
with mysql.connector.connec(**config) as cnx:
cnx._socket.set_connection_timeout(1) # workaround
with cnx.cusor() as cur:
cur.execute('SELECT SLEEP(10);') # executes the query
_ = cur.fetchone()
```
[16 Dec 2024 15:18]
Souma Kanti Ghosh
Posted by developer: The "connection_timeout" option is only going to be used as a timeout in seconds before which the connection with Connector/Python and the MySQL Server should be established. We've added the support for "read_timeout" and "write_timeout" to handle the query timeout scenarios instead. The option "read_timeout" will be used as the number of seconds up to which the connector's underlying socket should wait for the server to reply back before raising an `ReadTimeoutError`. The option "write_timeout" will be used as the number of seconds up to which the connector's underlying socket should spend to send data to the server before raising an `WriteTimeoutError`.
[8 Jan 2025 21:57]
Philip Olson
Posted by developer: Fixed as of the upcoming MySQL Connector/Python 9.2.0 release, and here's the proposed changelog entry from the documentation team: Added two new connection options: read_timeout (time limit to receive a response from the server) and write_timeout (time limit to send data to the server). Both options default to None, which sets the timeout to indefinitely. Thank you for the bug report.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.