Skip to content

Commit 6c9c981

Browse files
readyset-mysql: properly close mysql connections
When we have a MySQL connection open to upstream, before we close the connection, we need to send a COM_QUIT indicating we are about to terminate the connection. The write_command is an async function and by itself cannot be called as part of a destructor. We adjust the code to have a dedicated tokio task that will be responsible for sending the COM_QUIT command. Fixes: REA-5525 Closes: #1476 Release-Note-Core: Send a COM_QUIT command when closing a MySQL connection in order to avoid log flooding with aborted connection. Change-Id: Ibcb6dffdb55b4ba955b20b704c2f33162f8251c0 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/9085 Reviewed-by: Sidney Cammeresi <sac@readyset.io> Tested-by: Buildkite CI
1 parent fc819f9 commit 6c9c981

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

readyset-mysql/src/upstream.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::Arc;
44

55
use async_trait::async_trait;
66
use futures_util::Stream;
7-
use mysql_async::consts::{CapabilityFlags, StatusFlags};
7+
use mysql_async::consts::{CapabilityFlags, Command, StatusFlags};
88
use mysql_async::prelude::Queryable;
99
use mysql_async::{
1010
ChangeUserOpts, Column, Conn, Opts, OptsBuilder, ResultSetStream, Row, SslOpts, TxOpts,
@@ -473,5 +473,10 @@ impl UpstreamDatabase for MySqlUpstream {
473473
impl Drop for MySqlUpstream {
474474
fn drop(&mut self) {
475475
metrics::gauge!(recorded::CLIENT_UPSTREAM_CONNECTIONS).decrement(1.0);
476+
// Properly close the connection
477+
tokio::task::block_in_place(|| {
478+
let rt = tokio::runtime::Handle::current();
479+
let _ = rt.block_on(self.conn.write_command_data(Command::COM_QUIT, &[]));
480+
});
476481
}
477482
}

0 commit comments

Comments
 (0)