Closing a statement that has not started retrieval while there is a cursor opened in another statement causes the mariadb client to loose sync with the physical protocol state which in turn causes erratic behaviour in following interactions with the API: wrong return codes, crashes, hangs, etc
Correct behaviour should be for "mysql_stmt_close" to close the current cursor (regardless of what statement opened it). Then attempts to fetch data from a cursor while there is none active (regardless of the statement used in the mysql_stmt_fetch call) should return an error saying there is no cursor opened.
The interaction causing the issue to surface is:
create stmt1
prepare stmt1
create stmt2
prepare stmt2
fetch stmt1
close stmt2 -> from this point onwards the client is in an inconsistent state. Any interaction with the client from this point onwards will be subject to undeterministic behavior.
NOTE: The application I work on and where this causes wrong behaviour (crashes in my case) allows customers to choose how statements interact with connections. The customer can for instance use a connection per stmt or can decide to have concurrent statements using the same connection. This flexibility is in place since this application supports many other c connectors (oracle, postgres, etc) where retrieving data concurrently from different statements is supported by their respectives clients. In short, getting real useful errors indicating the interaction attempted is not supported by the underlying connector is ok but getting crashes or undeterministic behaviour is not.
For your convenience I have attached a patch.diff (generated from "master") with test cases that reproduce this issue. The patch adds this test cases in the "ps_bugs" executable that comes as part of the mariadb c connector test suite.
Also, I have done an initial investigation which shows that the culprit seems to be in line 379 (this is from "master" at the time of writing) in function mthd_stmt_flush_unbuffered() in file mariadb_stmt.c:
The problem is that mysql_stmt_close(stmt2) doesn't return an error (commands out of sync).
Georg Richter
added a comment - Thanks for your bug report.
I was able to reproduce this issue:
The problem is that mysql_stmt_close(stmt2) doesn't return an error (commands out of sync).
Thanks for acknowledging this bug so quickly. If you come up with a quick patch let me know and I will be happy to test it before you push it.
Josep Yus
added a comment - Thanks for acknowledging this bug so quickly. If you come up with a quick patch let me know and I will be happy to test it before you push it.
People
Georg Richter
Josep Yus
Votes:
0Vote for this issue
Watchers:
2Start 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":952.9000000059605,"ttfb":262.80000001192093,"pageVisibility":"visible","entityId":127294,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"0976218f-331d-4b7a-bf38-2a34c6e9967d","navigationType":0,"readyForUser":1035.1000000238419,"redirectCount":0,"resourceLoadedEnd":690.3000000119209,"resourceLoadedStart":273.2000000178814,"resourceTiming":[{"duration":73.19999998807907,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":273.2000000178814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":273.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":346.40000000596046,"responseStart":0,"secureConnectionStart":0},{"duration":73.60000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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","startTime":273.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":273.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":347.10000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":273.40000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":273.7000000178814,"connectEnd":273.7000000178814,"connectStart":273.7000000178814,"domainLookupEnd":273.7000000178814,"domainLookupStart":273.7000000178814,"fetchStart":273.7000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":350.30000001192093,"responseEnd":547.1000000238419,"responseStart":365.60000002384186,"secureConnectionStart":273.7000000178814},{"duration":416.40000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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","startTime":273.90000000596046,"connectEnd":273.90000000596046,"connectStart":273.90000000596046,"domainLookupEnd":273.90000000596046,"domainLookupStart":273.90000000596046,"fetchStart":273.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":351.30000001192093,"responseEnd":690.3000000119209,"responseStart":400.30000001192093,"secureConnectionStart":273.90000000596046},{"duration":137,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":274.10000002384186,"connectEnd":274.10000002384186,"connectStart":274.10000002384186,"domainLookupEnd":274.10000002384186,"domainLookupStart":274.10000002384186,"fetchStart":274.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":352.30000001192093,"responseEnd":411.10000002384186,"responseStart":369.5,"secureConnectionStart":274.10000002384186},{"duration":138.69999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":274.2000000178814,"connectEnd":274.2000000178814,"connectStart":274.2000000178814,"domainLookupEnd":274.2000000178814,"domainLookupStart":274.2000000178814,"fetchStart":274.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":353.10000002384186,"responseEnd":412.90000000596046,"responseStart":411.30000001192093,"secureConnectionStart":274.2000000178814},{"duration":100,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":274.5,"connectEnd":274.5,"connectStart":274.5,"domainLookupEnd":274.5,"domainLookupStart":274.5,"fetchStart":274.5,"redirectEnd":0,"redirectStart":0,"requestStart":358.10000002384186,"responseEnd":374.5,"responseStart":372.5,"secureConnectionStart":274.5},{"duration":78.40000000596046,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":274.7000000178814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":274.7000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":353.10000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":102.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":274.90000000596046,"connectEnd":274.90000000596046,"connectStart":274.90000000596046,"domainLookupEnd":274.90000000596046,"domainLookupStart":274.90000000596046,"fetchStart":274.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":359.90000000596046,"responseEnd":377.40000000596046,"responseStart":375,"secureConnectionStart":274.90000000596046},{"duration":82.60000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":275,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":275,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":357.60000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":110,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":275.2000000178814,"connectEnd":275.2000000178814,"connectStart":275.2000000178814,"domainLookupEnd":275.2000000178814,"domainLookupStart":275.2000000178814,"fetchStart":275.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":361.2000000178814,"responseEnd":385.2000000178814,"responseStart":381.10000002384186,"secureConnectionStart":275.2000000178814},{"duration":333.80000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":278,"connectEnd":278,"connectStart":278,"domainLookupEnd":278,"domainLookupStart":278,"fetchStart":278,"redirectEnd":0,"redirectStart":0,"requestStart":424.7000000178814,"responseEnd":611.8000000119209,"responseStart":601.1000000238419,"secureConnectionStart":278},{"duration":335.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":278.10000002384186,"connectEnd":278.10000002384186,"connectStart":278.10000002384186,"domainLookupEnd":278.10000002384186,"domainLookupStart":278.10000002384186,"fetchStart":278.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":453.2000000178814,"responseEnd":613.6000000238419,"responseStart":607.3000000119209,"secureConnectionStart":278.10000002384186},{"duration":164.40000000596046,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":689.7000000178814,"connectEnd":689.7000000178814,"connectStart":689.7000000178814,"domainLookupEnd":689.7000000178814,"domainLookupStart":689.7000000178814,"fetchStart":689.7000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":821.3000000119209,"responseEnd":854.1000000238419,"responseStart":853.3000000119209,"secureConnectionStart":689.7000000178814},{"duration":207.60000002384186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":909.5,"connectEnd":909.5,"connectStart":909.5,"domainLookupEnd":909.5,"domainLookupStart":909.5,"fetchStart":909.5,"redirectEnd":0,"redirectStart":0,"requestStart":1086.6000000238419,"responseEnd":1117.1000000238419,"responseStart":1115.800000011921,"secureConnectionStart":909.5},{"duration":176.69999998807907,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":946.7000000178814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":946.7000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1123.4000000059605,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":69,"responseStart":263,"responseEnd":274,"domLoading":267,"domInteractive":1133,"domContentLoadedEventStart":1133,"domContentLoadedEventEnd":1180,"domComplete":1457,"loadEventStart":1457,"loadEventEnd":1457,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1110},{"name":"bigPipe.sidebar-id.end","time":1110.800000011921},{"name":"bigPipe.activity-panel-pipe-id.start","time":1110.9000000059605},{"name":"bigPipe.activity-panel-pipe-id.end","time":1111.9000000059605},{"name":"activityTabFullyLoaded","time":1197.1000000238419}],"measures":[],"correlationId":"f4b383fd21b1b0","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":101,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks for your bug report.
I was able to reproduce this issue:
The problem is that mysql_stmt_close(stmt2) doesn't return an error (commands out of sync).