[CONC-589] First query after connection was lost fails when auto-reconnect enabled Created: 2022-04-19 Updated: 2022-04-20 |
|
| Status: | Open |
| Project: | MariaDB Connector/C |
| Component/s: | Other |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Frederik Haselmeier | Assignee: | Georg Richter |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
The reconnect feature that can be enabled by setting MYSQL_OPT_RECONNECT to true seems to always fail the first query after the connection was lost with the error "Lost connection to server during query". The expected behaviour (which is also the behaviour of libmysql) would be for the connection to be re-established without any query failing. The MySQL documentation specifically mentions that any queries that are sent after the connection was lost will be retried if auto-reconnect is enabled but I could not find any documentation like this for the MariaDB C Connector. Here is a small piece of code that can be used to replicate the issue. It requires the MySQL/MariaDB server to be restarted within the 10 seconds waiting period to demonstrate the issue.
Output using libmysql:
Output using libmariadb:
|
| Comments |
| Comment by Georg Richter [ 2022-04-20 ] |
|
Not throwing an error might lead to inconsistencies. Consider the following cases: Non transactional:
Do you really want to insert a NULL value? Transactional:
Does it make sense to delete rows with newval=0 when previous statements were rolled back? |
| Comment by Frederik Haselmeier [ 2022-04-20 ] |
|
While your example will break when using auto-reconnect, this is also explicitly stated by the MySQL documentation. If auto-reconnect fails the first query, then this feature is almost entirely useless. After running any networked command I will have to manually check if the connection was lost anyways and then retry if applicable, in which case I could also just add the one additional line of running mariadb_reconnect. I just want to point out again that libmysql (at least the version I tested, 6.1.11) does not fail the first query, which is the behaviour I would expect from the MySQL documentation. Unfortunately there is seemingly no documentation for what MariaDB does when an auto-reconnect happens so I assumed it would work the same as with MySQL. |