Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The diesel 2.1.5 version cannot close the tls connection #3996

Closed
12Saturn opened this issue Apr 19, 2024 · 7 comments · Fixed by #4027
Closed

The diesel 2.1.5 version cannot close the tls connection #3996

12Saturn opened this issue Apr 19, 2024 · 7 comments · Fixed by #4027

Comments

@12Saturn
Copy link

12Saturn commented Apr 19, 2024

Versions

  • **Rust:1.75.0
  • **Diesel:2.1.5
  • **Database:mysql 8.0.36
  • **Operating System:mac
  • **Mysql client:8.0.22

Problem Description

When using diesel to connect to mysql, I do not want to use SSL connection, but adding ‘ssl_mode=disabled’ does not work

conn mysql :

#[tokio::main]
async fn main() {
              let database_url = "mysql://root:123456@127.0.0.1:3306/test?ssl_mode=disabled";
              let mut tmp_conn = diesel::mysql::MysqlConnection::establish(&database_url)
                  .expect("Failed to connect db");
              tmp_conn.run_pending_migrations(MYSQL_MIGRATIONS).unwrap();
              let manager = AsyncDieselConnectionManager::<AsyncMysqlConnection>::new(database_url);
              let pool = MySqlPool::builder()
                  .build(manager)
                  .await
                  .expect("Failed to create db pool");
}
tokio = { version = "1.27.0", features = ["sync", "rt", "time", "macros", "rt-multi-thread"] }
diesel = { version = "2.1.5", features = ["mysql", "postgres", "serde_json", "chrono"] }
diesel-async = { version = "0.4.1", features = ["bb8", "postgres", "mysql"] }
diesel_migrations = "2.1.0"

wifeshark Indicates the result of packet capture:

sc_20240419163931

@12Saturn 12Saturn added the bug label Apr 19, 2024
@weiznich
Copy link
Member

Thanks for opening this bug report. Can you please complete the bug template as otherwise this report is not actionable for anyone due to missing details. Additionally you want to provide more details that just stating that "something" does not work. You might want to include additional details like a minimal reproducible example, information about your database system and your client libraries and your environment configuration.

@12Saturn
Copy link
Author

Thank you very much for your reply. I have added the test examples and test results

@weiznich
Copy link
Member

Thanks for adding the details. I'm sorry but there are still some important points missing until this becomes actionable:

  • Your application uses connections from diesel_async and diesel. Can you clarify if that problem happens with the connection from diesel_async or from diesel. In the former case that's the wrong issue tracker here.
  • It's still missing important information about the exact version of mysqlclient and mysql you are using, I fear without that it's not possible to do anything

@12Saturn
Copy link
Author

Thank you very much for your reply. After removing diesel_async, I used diesel to connect mysql and the same problem occurred again

#[tokio::main]
async fn main()  {
    let database_url = "mysql://root:123456@127.0.0.1:3306/test?ssl_mode=disabled";
    let mut conn = diesel::mysql::MysqlConnection::establish(&database_url)
        .expect("Failed to connect db");
    conn.batch_execute("select 1").unwrap();
}

result:
sc_1

@weiznich
Copy link
Member

Thanks for confirming that this is in fact a diesel and not a diesel-async issue. That still leaves the important question about your libmysqlclient unanswered.

@12Saturn
Copy link
Author

I'm sorry I forgot to add yesterday, libmysqlclient version is 8.0.22

@weiznich
Copy link
Member

Thanks for adding this information. I think I can explain what's wrong here. Diesel sets MYSQL_OPT_SSL_MODE for this option, which refers to the value 42 according to the bundled bindings (generated from mysqlclient 5.7.11 a few years back. It seems that this value changed with the release of mysql 8.0 to 35. That means it now tries to use an unsupported value there and it seems like this is just ignored.

The fix for this would be to update the bundled bundings in the mysqlclient-sys crate. (Which is not something that is straight forward without breaking compatibility with older libmysqlclient versions). I already started doing that in sgrif/mysqlclient-sys#40, which is just not complete yet. Your contribution is welcome there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants