Some library functions like mysql_library_init() or mysql_init() may fail and on error they do not return MYSQL* structure. To detect their error code and message it was possible to call mysql_errno(NULL) and mysql_error(NULL) to retrieve them. This is working fine since MySQL version 5.0.60 (for 5.0 series) and globally since 5.1.24 (for 5.1 and new series). But MariaDB 10.2 stopped using MySQL client implementation (where it worked fine) and started to use MariaDB Connector/C which does not provide meaningful value from mysql_errno(NULL) and mysql_error(NULL) calls. It always returns 0 and empty string. So when mysql_library_init() or mysql_init() fails, caller does not why. Since MariaDB 10.2 started using MariaDB Connector/C there is no way to retrieve error code or message for these functions. So please fix mysql_errno(NULL) and mysql_error(NULL) functions to return real error code/messages for last mysql_* function call.
Hm... if problem with global variable is when threads are used, then in C11, variable can be declared with _Thread_local. Or for older C versions you can use compiler extensions for TLS, e.g. in gcc (and also clang and icc) there is __thread keyword, in msvc there is __declspec(thread) keyword.
Pali
added a comment - Hm... if problem with global variable is when threads are used, then in C11, variable can be declared with _Thread_local. Or for older C versions you can use compiler extensions for TLS, e.g. in gcc (and also clang and icc) there is __thread keyword, in msvc there is __declspec(thread) keyword.
Is there any reason why to not use thread local variables in case global variables is a problem? Anyway, it is a problem that these global variables would not be thread-safe?
Pali
added a comment - Is there any reason why to not use thread local variables in case global variables is a problem? Anyway, it is a problem that these global variables would not be thread-safe?
In MariaDB Connector/C we don't have any error messages, in case of an error in mysql_server_init application should check errno or WinGetLastErrror(). Even using a global variable would not be useful, since it will not be thread safe.
int STDCALL mysql_server_init(int argc __attribute__((unused)),
char **argv __attribute__((unused)),
char **groups __attribute__((unused)))
{
#ifdef _WIN32
BOOL ret = InitOnceExecuteOnce(&init_once, win_init_once, NULL, NULL);
return ret? 0: 1;
#else
return pthread_once(&init_once, mysql_once_init);
#endif
}
The embedded library might be different, it's not using Connector/C.
Georg Richter
added a comment - Hi Pali,
Happy holidays!
In MariaDB Connector/C we don't have any error messages, in case of an error in mysql_server_init application should check errno or WinGetLastErrror(). Even using a global variable would not be useful, since it will not be thread safe.
int STDCALL mysql_server_init( int argc __attribute__((unused)),
char **argv __attribute__((unused)),
char **groups __attribute__((unused)))
{
#ifdef _WIN32
BOOL ret = InitOnceExecuteOnce(&init_once, win_init_once, NULL, NULL);
return ret? 0 : 1 ;
# else
return pthread_once(&init_once, mysql_once_init);
#endif
}
The embedded library might be different, it's not using Connector/C.
pthread_once() does not set errno. Instead error is indicated by the return value. pthread functions differs here from other POSIX functions. Anyway, global variables can be also thread safe (one example is errno), variable just needs to be declared as thread local.
The bad thing is that MariaDB Connector/C has different API for error handling than the original MySQL library and also differnet than MariaDB embedded library. This makes problems for applications as they either need to add tons of #ifdef-s for MariaDB support or ignore error at all.
Pali
added a comment - pthread_once() does not set errno. Instead error is indicated by the return value. pthread functions differs here from other POSIX functions. Anyway, global variables can be also thread safe (one example is errno), variable just needs to be declared as thread local.
The bad thing is that MariaDB Connector/C has different API for error handling than the original MySQL library and also differnet than MariaDB embedded library. This makes problems for applications as they either need to add tons of #ifdef-s for MariaDB support or ignore error at all.
People
Georg Richter
Pali
Votes:
0Vote for this issue
Watchers:
2Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":722.8000001907349,"ttfb":175.60000038146973,"pageVisibility":"visible","entityId":71002,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"8830ee89-37e4-4fb2-bb6d-107a2b49e1c1","navigationType":0,"readyForUser":765.8000001907349,"redirectCount":0,"resourceLoadedEnd":758.5,"resourceLoadedStart":181.30000019073486,"resourceTiming":[{"duration":12.399999618530273,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":181.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":181.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":193.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":13.59999942779541,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":181.60000038146973,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":181.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":195.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":78,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":181.69999980926514,"connectEnd":181.69999980926514,"connectStart":181.69999980926514,"domainLookupEnd":181.69999980926514,"domainLookupStart":181.69999980926514,"fetchStart":181.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":181.69999980926514,"responseEnd":259.69999980926514,"responseStart":259.69999980926514,"secureConnectionStart":181.69999980926514},{"duration":127,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":181.80000019073486,"connectEnd":181.80000019073486,"connectStart":181.80000019073486,"domainLookupEnd":181.80000019073486,"domainLookupStart":181.80000019073486,"fetchStart":181.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":181.80000019073486,"responseEnd":308.80000019073486,"responseStart":308.80000019073486,"secureConnectionStart":181.80000019073486},{"duration":130.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":182,"connectEnd":182,"connectStart":182,"domainLookupEnd":182,"domainLookupStart":182,"fetchStart":182,"redirectEnd":0,"redirectStart":0,"requestStart":182,"responseEnd":312.6000003814697,"responseStart":312.6000003814697,"secureConnectionStart":182},{"duration":131,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":182.10000038146973,"connectEnd":182.10000038146973,"connectStart":182.10000038146973,"domainLookupEnd":182.10000038146973,"domainLookupStart":182.10000038146973,"fetchStart":182.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":182.10000038146973,"responseEnd":313.1000003814697,"responseStart":313.1000003814697,"secureConnectionStart":182.10000038146973},{"duration":131.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":182.19999980926514,"connectEnd":182.19999980926514,"connectStart":182.19999980926514,"domainLookupEnd":182.19999980926514,"domainLookupStart":182.19999980926514,"fetchStart":182.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":182.19999980926514,"responseEnd":313.5,"responseStart":313.5,"secureConnectionStart":182.19999980926514},{"duration":131.89999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":182.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":314.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":131.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":182.4000005722046,"connectEnd":182.4000005722046,"connectStart":182.4000005722046,"domainLookupEnd":182.4000005722046,"domainLookupStart":182.4000005722046,"fetchStart":182.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":182.4000005722046,"responseEnd":313.9000005722046,"responseStart":313.9000005722046,"secureConnectionStart":182.4000005722046},{"duration":131.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":182.60000038146973,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":314.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":132.0999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":182.60000038146973,"connectEnd":182.60000038146973,"connectStart":182.60000038146973,"domainLookupEnd":182.60000038146973,"domainLookupStart":182.60000038146973,"fetchStart":182.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":182.60000038146973,"responseEnd":314.69999980926514,"responseStart":314.69999980926514,"secureConnectionStart":182.60000038146973},{"duration":411.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":183.30000019073486,"connectEnd":183.30000019073486,"connectStart":183.30000019073486,"domainLookupEnd":183.30000019073486,"domainLookupStart":183.30000019073486,"fetchStart":183.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":183.30000019073486,"responseEnd":595.1000003814697,"responseStart":595.1000003814697,"secureConnectionStart":183.30000019073486},{"duration":431.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":183.30000019073486,"connectEnd":183.30000019073486,"connectStart":183.30000019073486,"domainLookupEnd":183.30000019073486,"domainLookupStart":183.30000019073486,"fetchStart":183.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":183.30000019073486,"responseEnd":615,"responseStart":615,"secureConnectionStart":183.30000019073486},{"duration":127.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":474.5,"connectEnd":474.5,"connectStart":474.5,"domainLookupEnd":474.5,"domainLookupStart":474.5,"fetchStart":474.5,"redirectEnd":0,"redirectStart":0,"requestStart":474.5,"responseEnd":602.3000001907349,"responseStart":602.3000001907349,"secureConnectionStart":474.5},{"duration":81.89999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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","startTime":669.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":669.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":751.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":81.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/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","startTime":670.5,"connectEnd":670.5,"connectStart":670.5,"domainLookupEnd":670.5,"domainLookupStart":670.5,"fetchStart":670.5,"redirectEnd":0,"redirectStart":0,"requestStart":670.5,"responseEnd":752.1000003814697,"responseStart":752.1000003814697,"secureConnectionStart":670.5},{"duration":87.59999942779541,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/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","startTime":670.9000005722046,"connectEnd":670.9000005722046,"connectStart":670.9000005722046,"domainLookupEnd":670.9000005722046,"domainLookupStart":670.9000005722046,"fetchStart":670.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":670.9000005722046,"responseEnd":758.5,"responseStart":758.5,"secureConnectionStart":670.9000005722046},{"duration":89.19999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":701.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":701.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":790.6000003814697,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":59,"responseStart":175,"responseEnd":179,"domLoading":179,"domInteractive":841,"domContentLoadedEventStart":841,"domContentLoadedEventEnd":883,"domComplete":1138,"loadEventStart":1138,"loadEventEnd":1138,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":800.3000001907349},{"name":"bigPipe.sidebar-id.end","time":801},{"name":"bigPipe.activity-panel-pipe-id.start","time":801.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":803.6000003814697},{"name":"activityTabFullyLoaded","time":904.3000001907349}],"measures":[],"correlationId":"e845284ef28cd0","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":70,"dbReadsTimeInMs":9,"dbConnsTimeInMs":15,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Afaik, the NULL parameter was used for embedded only, since the internal error codes in libmysql are not thread safe.