Skip to content

Commit

Permalink
feedback plugin: abort sending the report on server shutdown
Browse files Browse the repository at this point in the history
network timeouts might be rather large and feedback plugin
waits forever for the sender thread to exit.

an alternative could've been to use GNU-specific pthread_timedjoin_np(),
where _np mean "not portable".
  • Loading branch information
vuvova committed Apr 13, 2024
1 parent 6a4ac4c commit 8bc3241
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions plugin/feedback/feedback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ static int free(void *p)
shutdown_plugin= true;
mysql_cond_signal(&sleep_condition);
mysql_mutex_unlock(&sleep_mutex);

for (uint i= 0; i < url_count; i++)
urls[i]->abort();

pthread_join(sender_thread, NULL);

mysql_mutex_destroy(&sleep_mutex);
Expand Down
1 change: 1 addition & 0 deletions plugin/feedback/feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Url {

const char *url() { return full_url.str; }
size_t url_length() { return full_url.length; }
virtual void abort() = 0;
virtual int send(const char* data, size_t data_length) = 0;
virtual int set_proxy(const char *proxy, size_t proxy_len)
{
Expand Down
18 changes: 15 additions & 3 deletions plugin/feedback/url_http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ static const uint FOR_WRITING= 1;
class Url_http: public Url {
protected:
const LEX_STRING host, port, path;
bool ssl;
LEX_STRING proxy_host, proxy_port;
my_socket fd;
bool ssl;

bool use_proxy()
{
Expand All @@ -47,7 +48,8 @@ class Url_http: public Url {

Url_http(LEX_STRING &url_arg, LEX_STRING &host_arg,
LEX_STRING &port_arg, LEX_STRING &path_arg, bool ssl_arg) :
Url(url_arg), host(host_arg), port(port_arg), path(path_arg), ssl(ssl_arg)
Url(url_arg), host(host_arg), port(port_arg), path(path_arg),
fd(INVALID_SOCKET), ssl(ssl_arg)
{
proxy_host.length= 0;
}
Expand All @@ -60,6 +62,7 @@ class Url_http: public Url {
}

public:
void abort();
int send(const char* data, size_t data_length);
int set_proxy(const char *proxy, size_t proxy_len)
{
Expand Down Expand Up @@ -158,13 +161,18 @@ Url* http_create(const char *url, size_t url_length)
return new Url_http(full_url, host, port, path, ssl);
}

void Url_http::abort()
{
if (fd != INVALID_SOCKET)
closesocket(fd); // interrupt I/O waits
}

/* do the vio_write and check that all data were sent ok */
#define write_check(VIO, DATA, LEN) \
(vio_write((VIO), (uchar*)(DATA), (LEN)) != (LEN))

int Url_http::send(const char* data, size_t data_length)
{
my_socket fd= INVALID_SOCKET;
char buf[1024];
size_t len= 0;

Expand All @@ -180,6 +188,7 @@ int Url_http::send(const char* data, size_t data_length)
return 1;
}

DBUG_ASSERT(fd == INVALID_SOCKET);
for (addr= addrs; addr != NULL; addr= addr->ai_next)
{
fd= socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
Expand Down Expand Up @@ -208,6 +217,7 @@ int Url_http::send(const char* data, size_t data_length)
sql_print_error("feedback plugin: vio_new failed for url '%s'",
full_url.str);
closesocket(fd);
fd= INVALID_SOCKET;
return 1;
}

Expand Down Expand Up @@ -236,6 +246,7 @@ int Url_http::send(const char* data, size_t data_length)
free_vio_ssl_acceptor_fd(ssl_fd);
closesocket(fd);
vio_delete(vio);
fd= INVALID_SOCKET;
return 1;
}
}
Expand Down Expand Up @@ -334,6 +345,7 @@ int Url_http::send(const char* data, size_t data_length)
}
#endif

fd= INVALID_SOCKET;
return res;
}

Expand Down

0 comments on commit 8bc3241

Please sign in to comment.