Skip to content

Commit

Permalink
[vio] PS-5327 proxy protocol-related memory leak at shutdown
Browse files Browse the repository at this point in the history
The Problem:
When proxy protocol is enabled, MySQL won't cleanup
vio_pp_networks variable at shutdown.

Solution:
Cleanup allocated networks at shutdown.
Enhanced proxy_protocol test to cover this scenario.
  • Loading branch information
altmannmarcelo authored and dlenev committed Oct 17, 2024
1 parent 259513e commit 17d470c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/violite.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ struct st_vio_network {
};

void vio_proxy_protocol_add(const st_vio_network &net) noexcept;
void vio_proxy_cleanup() noexcept;
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
int vio_fastsend(MYSQL_VIO vio);
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/r/proxy_protocol.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT @@proxy_protocol_networks;
@@proxy_protocol_networks
*
# An unproxied client connection should be rejected if proxying enabled on the server
Got one of the listed errors
# PS-5327 proxy protocol-related memory leak at shutdown
# restart
11 changes: 11 additions & 0 deletions mysql-test/t/proxy_protocol.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT @@proxy_protocol_networks;

--echo # An unproxied client connection should be rejected if proxying enabled on the server
--disable_query_log
--error ER_BAD_HOST_ERROR,CR_SERVER_LOST
connect (err,"127.0.0.1",root,,,$MASTER_MYPORT,);
--enable_query_log

--echo # PS-5327 proxy protocol-related memory leak at shutdown
# Restart the server
--source include/restart_mysqld.inc
5 changes: 4 additions & 1 deletion vio/vio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,10 @@ void vio_delete(Vio *vio) { internal_vio_delete(vio); }
components below it when application finish
*/
void vio_end() { vio_ssl_end(); }
void vio_end() {
vio_ssl_end();
vio_proxy_cleanup();
}

struct vio_string {
const char *m_str;
Expand Down
2 changes: 2 additions & 0 deletions vio/viosocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ void vio_proxy_protocol_add(const struct st_vio_network &net) noexcept {
memcpy(&vio_pp_networks[vio_pp_networks_nb - 1], &net, sizeof(net));
}

void vio_proxy_cleanup() noexcept { my_free(vio_pp_networks); }

/* Check whether a connection from this source address must provide the proxy
protocol header */
static bool vio_client_must_be_proxied(const struct sockaddr *p_addr) noexcept {
Expand Down

0 comments on commit 17d470c

Please sign in to comment.