Skip to content

MDEV-30432 replace curl rest connector with libcurl usage#5071

Draft
grooverdan wants to merge 7 commits into
MariaDB:mainfrom
grooverdan:13.1-anel-connect-curl-MDEV-30432-v1-after-review
Draft

MDEV-30432 replace curl rest connector with libcurl usage#5071
grooverdan wants to merge 7 commits into
MariaDB:mainfrom
grooverdan:13.1-anel-connect-curl-MDEV-30432-v1-after-review

Conversation

@grooverdan
Copy link
Copy Markdown
Member

Rather than its fragile and gastly use of the curl executable.

an3l and others added 2 commits May 13, 2026 16:56
- Remove GetRest occurance
- Add libcurl feature to ConnectSE
- This patch closes MDEV-26727 (tested with Docker)
@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label May 13, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the Casablanca (cpprestsdk) dependency and external curl process calls with direct libcurl integration for the CONNECT storage engine's REST support. The changes involve removing restget.cpp, updating build configurations, and implementing new curl_init, curl_run, and curl_deinit methods within the RESTDEF class. Feedback identifies critical thread-safety concerns regarding the placement of global curl initialization, a dangling pointer bug in DefineAM, and potential null pointer dereferences. Further improvements are suggested for file handling robustness, error reporting, URL buffer sizing, and the removal of unused data structures.

Comment on lines +201 to +228
int RESTDEF::curl_init(PGLOBAL g)
{
CURLcode curl_res = curl_global_init(CURL_GLOBAL_ALL);
if (curl_res != CURLE_OK)
{
snprintf(g->Message, sizeof(g->Message),
"unable to initialize curl library, "
"curl returned this error code: %u "
"with the following error message: %s",
curl_res, curl_easy_strerror(curl_res));
return 1;
}
curl_inited = true;
return 0;
}


/***********************************************************************/
/* curl_deinit: Cleanup curl */
/***********************************************************************/
void RESTDEF::curl_deinit()
{
if (curl_inited)
{
curl_global_cleanup();
curl_inited = false;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The functions curl_global_init and curl_global_cleanup are not thread-safe and are intended to be called exactly once per process. Calling them within curl_init and curl_deinit (which is called by the RESTDEF destructor) means they will be executed every time a REST table is defined or queried. In a multi-threaded environment like MariaDB, this will lead to race conditions, memory corruption, or crashes if multiple threads access REST tables simultaneously. These calls should be moved to the global plugin initialization and de-initialization routines.

Comment thread storage/connect/tabrest.cpp Outdated
Comment thread storage/connect/tabrest.cpp Outdated
Comment thread storage/connect/tabrest.cpp Outdated
Comment on lines +283 to +287
if (is_error)
{
snprintf(g->Message, sizeof(g->Message), "server error");
return 1;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error message "server error" is too generic. Including the HTTP response code would greatly improve debuggability when a REST request fails with a non-2xx status.

  if (is_error)
  {
    snprintf(g->Message, sizeof(g->Message), "Server returned error code %ld", http_code);
    return 1;
  }

Comment thread storage/connect/tabrest.cpp Outdated
Comment thread storage/connect/tabrest.h Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Foundation Pull requests created by MariaDB Foundation

Development

Successfully merging this pull request may close these issues.

2 participants