Skip to content

Commit

Permalink
fix hangs on authenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 committed Mar 3, 2022
1 parent c9e9360 commit 670358a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ common-tracing = { path = "../common/tracing" }

# Github dependencies
cargo-license = { git = "https://github.com/datafuse-extras/cargo-license", rev = "f1ce4a2" }
msql-srv = { git = "https://github.com/datafuse-extras/msql-srv", rev = "70aa0b2" }
msql-srv = { git = "https://github.com/flaneur2020/msql-srv", rev = "6134ff" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "472f5b6" }

# Crates.io dependencies
Expand Down
36 changes: 18 additions & 18 deletions query/src/servers/mysql/mysql_interactive_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct InteractiveWorker<W: std::io::Write> {
}

#[async_trait::async_trait]
impl<W: std::io::Write + Send> AsyncMysqlShim<W> for InteractiveWorker<W> {
impl<W: std::io::Write + Send + Sync> AsyncMysqlShim<W> for InteractiveWorker<W> {
type Error = ErrorCode;

fn version(&self) -> &str {
Expand All @@ -78,34 +78,33 @@ impl<W: std::io::Write + Send> AsyncMysqlShim<W> for InteractiveWorker<W> {
self.salt
}

fn authenticate(
async fn authenticate(
&self,
_auth_plugin: &str,
username: &[u8],
salt: &[u8],
auth_data: &[u8],
) -> bool {
let username = String::from_utf8_lossy(username);
let info = CertifiedInfo::create(&username, auth_data, &self.client_addr);
let client_addr = self.client_addr.clone();
let info = CertifiedInfo::create(&username, auth_data, &client_addr);

let authenticate = self.base.authenticate(salt, info);
futures::executor::block_on(async move {
match authenticate.await {
Ok(res) => res,
Err(failure) => {
tracing::error!(
"MySQL handler authenticate failed, \
match authenticate.await {
Ok(res) => res,
Err(failure) => {
tracing::error!(
"MySQL handler authenticate failed, \
user_name: {}, \
client_address: {}, \
failure_cause: {}",
username,
self.client_addr,
failure
);
false
}
username,
client_addr,
failure
);
false
}
})
}
}

async fn on_prepare<'a>(
Expand Down Expand Up @@ -215,9 +214,10 @@ impl<W: std::io::Write> InteractiveWorkerBase<W> {
let client_ip = info.user_client_address.split(':').collect::<Vec<_>>()[0];

let ctx = self.session.create_query_context().await?;
let user_info = user_manager
let user_info_res = user_manager
.get_user_with_client_ip(&ctx.get_tenant(), user_name, client_ip)
.await?;
.await;
let user_info = user_info_res?;

let authed = user_info.auth_info.auth_mysql(&info.user_password, salt)?;
if authed {
Expand Down

0 comments on commit 670358a

Please sign in to comment.