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 second query that runs after the connection succeeds and the connection is re-established.
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.
#include <iostream>
#include <thread>
#include <chrono>
#include <mysql/mysql.h>
usingnamespace std::chrono_literals;
void runQuery(MYSQL *sql) {
std::string queryStr = "SELECT 1";
MYSQL_RES *resultSet;
if (mysql_real_query(sql, queryStr.c_str(), queryStr.size()) ||
Not throwing an error might lead to inconsistencies.
Consider the following cases:
Non transactional:
1 create table t1(a int);
2. set @a:=1
drop connection here
3. insert into t1 values (@a);
Do you really want to insert a NULL value?
Transactional:
1. BEGIN
2. UPDATE t1 SET newval=1, value=? where DATE > ?
drop connection here
3. DELETE FROM t1 where newval=0
4. END
Does it make sense to delete rows with newval=0 when previous statements were rolled back?
Georg Richter
added a comment - Not throwing an error might lead to inconsistencies.
Consider the following cases:
Non transactional:
1 create table t1(a int);
2. set @a:=1
drop connection here
3. insert into t1 values (@a);
Do you really want to insert a NULL value?
Transactional:
1. BEGIN
2. UPDATE t1 SET newval=1, value=? where DATE > ?
drop connection here
3. DELETE FROM t1 where newval=0
4. END
Does it make sense to delete rows with newval=0 when previous statements were rolled back?
While your example will break when using auto-reconnect, this is also explicitly stated by the MySQL documentation.
Auto-reconnect is almost certainly only useful in cases where one does not have stateful queries, such as in the example I posted above. This is also why the option is disabled by default.
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.
Frederik Haselmeier
added a comment - - edited While your example will break when using auto-reconnect, this is also explicitly stated by the MySQL documentation .
Auto-reconnect is almost certainly only useful in cases where one does not have stateful queries, such as in the example I posted above. This is also why the option is disabled by default.
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.
People
Georg Richter
Frederik Haselmeier
Votes:
0Vote for this issue
Watchers:
3Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1069.5999999046326,"ttfb":298.2999997138977,"pageVisibility":"visible","entityId":110095,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"6b71bca3-433f-483a-9f56-1a99de735a42","navigationType":0,"readyForUser":1197.8999996185303,"redirectCount":0,"resourceLoadedEnd":1237.0999999046326,"resourceLoadedStart":309.8999996185303,"resourceTiming":[{"duration":119,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":309.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":309.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":428.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":119.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":310.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":310.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":429.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":182.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":310.59999990463257,"connectEnd":310.59999990463257,"connectStart":310.59999990463257,"domainLookupEnd":310.59999990463257,"domainLookupStart":310.59999990463257,"fetchStart":310.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":310.59999990463257,"responseEnd":492.7999997138977,"responseStart":492.7999997138977,"secureConnectionStart":310.59999990463257},{"duration":300.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":311.2999997138977,"connectEnd":311.2999997138977,"connectStart":311.2999997138977,"domainLookupEnd":311.2999997138977,"domainLookupStart":311.2999997138977,"fetchStart":311.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":311.2999997138977,"responseEnd":612.0999999046326,"responseStart":612.0999999046326,"secureConnectionStart":311.2999997138977},{"duration":359.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":311.5,"connectEnd":311.5,"connectStart":311.5,"domainLookupEnd":311.5,"domainLookupStart":311.5,"fetchStart":311.5,"redirectEnd":0,"redirectStart":0,"requestStart":311.5,"responseEnd":670.6999998092651,"responseStart":670.5999999046326,"secureConnectionStart":311.5},{"duration":375.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":311.59999990463257,"connectEnd":311.59999990463257,"connectStart":311.59999990463257,"domainLookupEnd":311.59999990463257,"domainLookupStart":311.59999990463257,"fetchStart":311.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":311.59999990463257,"responseEnd":686.8999996185303,"responseStart":686.8999996185303,"secureConnectionStart":311.59999990463257},{"duration":375.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":311.8999996185303,"connectEnd":311.8999996185303,"connectStart":311.8999996185303,"domainLookupEnd":311.8999996185303,"domainLookupStart":311.8999996185303,"fetchStart":311.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":311.8999996185303,"responseEnd":687.5,"responseStart":687.5,"secureConnectionStart":311.8999996185303},{"duration":391,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":312.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":703.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":375.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":312.5,"connectEnd":312.5,"connectStart":312.5,"domainLookupEnd":312.5,"domainLookupStart":312.5,"fetchStart":312.5,"redirectEnd":0,"redirectStart":0,"requestStart":312.5,"responseEnd":688.1999998092651,"responseStart":688.1999998092651,"secureConnectionStart":312.5},{"duration":390.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":312.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":703.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":375.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":313,"connectEnd":313,"connectStart":313,"domainLookupEnd":313,"domainLookupStart":313,"fetchStart":313,"redirectEnd":0,"redirectStart":0,"requestStart":313,"responseEnd":688.7999997138977,"responseStart":688.7999997138977,"secureConnectionStart":313},{"duration":701.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":318.5,"connectEnd":318.5,"connectStart":318.5,"domainLookupEnd":318.5,"domainLookupStart":318.5,"fetchStart":318.5,"redirectEnd":0,"redirectStart":0,"requestStart":318.5,"responseEnd":1020.1999998092651,"responseStart":1020.1999998092651,"secureConnectionStart":318.5},{"duration":827.1999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":318.5,"connectEnd":318.5,"connectStart":318.5,"domainLookupEnd":318.5,"domainLookupStart":318.5,"fetchStart":318.5,"redirectEnd":0,"redirectStart":0,"requestStart":318.5,"responseEnd":1145.6999998092651,"responseStart":1145.6999998092651,"secureConnectionStart":318.5},{"duration":293.7000002861023,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":733.8999996185303,"connectEnd":733.8999996185303,"connectStart":733.8999996185303,"domainLookupEnd":733.8999996185303,"domainLookupStart":733.8999996185303,"fetchStart":733.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":733.8999996185303,"responseEnd":1027.5999999046326,"responseStart":1027.5999999046326,"secureConnectionStart":733.8999996185303},{"duration":275.59999990463257,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1056.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1056.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1332.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":156.2000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1080.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1080.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1237.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":65,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1081.7999997138977,"connectEnd":1081.7999997138977,"connectStart":1081.7999997138977,"domainLookupEnd":1081.7999997138977,"domainLookupStart":1081.7999997138977,"fetchStart":1081.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1081.7999997138977,"responseEnd":1146.7999997138977,"responseStart":1146.7999997138977,"secureConnectionStart":1081.7999997138977},{"duration":66.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1082.2999997138977,"connectEnd":1082.2999997138977,"connectStart":1082.2999997138977,"domainLookupEnd":1082.2999997138977,"domainLookupStart":1082.2999997138977,"fetchStart":1082.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1082.2999997138977,"responseEnd":1149.0999999046326,"responseStart":1149.0999999046326,"secureConnectionStart":1082.2999997138977}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":122,"responseStart":298,"responseEnd":323,"domLoading":302,"domInteractive":1381,"domContentLoadedEventStart":1381,"domContentLoadedEventEnd":1431,"domComplete":1799,"loadEventStart":1799,"loadEventEnd":1801,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1343.0999999046326},{"name":"bigPipe.sidebar-id.end","time":1344},{"name":"bigPipe.activity-panel-pipe-id.start","time":1344.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1345.5},{"name":"activityTabFullyLoaded","time":1444.3999996185303}],"measures":[],"correlationId":"75e0cc53a052e3","effectiveType":"4g","downlink":9,"rtt":0,"serverDuration":103,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Not throwing an error might lead to inconsistencies.
Consider the following cases:
Non transactional:
1 create table t1(a int);
2. set @a:=1
3. insert into t1 values (@a);
Do you really want to insert a NULL value?
Transactional:
1. BEGIN
2. UPDATE t1 SET newval=1, value=? where DATE > ?
3. DELETE FROM t1 where newval=0
4. END
Does it make sense to delete rows with newval=0 when previous statements were rolled back?