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
Using unsupported buffer type: 253 (parameter: 1)
when trying to use the CLI
#3929
Comments
As always happens, just after opening this issue i have managed to solve it 🤦🏻 I'm assuming this is a compatability issue between Diesel and MySql 8.3. I solved this by:
|
Thanks for opening this issue and adding these details. I would say it is expected that diesel works with the latest libmysqlclient version, therefore that's likely a bug. So I reopen this issue. Can you verify a detail: You can fix this by just using a older libmysqlclient version with the newer database? (So client 8.0, database 8.3) |
Correct, the 8.0 |
I also faced this issue when re-installing MySQL on MacOS. I first saw the below overflow/underflow error when querying a table that had not been touched in a long time:
And finally came across the "Using unsupported buffer type: 253 (parameter: 1)" error when trying to list migrations, which pointed me to this issue. I had to run
Thank you @watsom27 you're a lifesaver - this was doing my head in! |
That really sounds like something changed fundamentally in the mysql client headers at the c side. In turn that means we likely need to update the generated bindings for that + adjust some code in diesel. Unfortunately I do currently not have the capacity to do all of that on my own, so I need to mark this as accepting contributions and let it sit here till someone spends the time to perform the necessary steps. (Given that this seems to happen on a minor mysql release I highly question their approach of handling breaking changes…) |
@weiznich I would be happy to have a go at this, but having looked at the codebase I have no idea where to start. If you could point me in the general direction of the code this change would involve, or if there is any developer documentation I will happily take a look. Thanks |
@watsom27 It's totally fine to ask for help where to start and what to try. I know that the codebase is large and complex, so you are not expected to solve this completely on your own. I would likely start by running at these tests with the new libmysqlclient version. diesel/diesel/src/mysql/connection/bind.rs Line 736 in ad8ef47
Given the error message in the bug report I would expect that just running them will produce some similar error. That should give use more information about which type is affected. Starting from there I would likely check the header files of the new and old libmysqlclient version to check if the relevant bind type for that sql type has changed. Maybe add some println statements in there and see how the values change between versions. If we have more information about which type is affected and why that happens we can discuss ways how to solve that without breaking compatibility with the old versions. |
Share some investigation here (note: the line number might offset by 2-3 lines since I added some debug print). for test in // failed on this query
sql_query("SELECT 1 AS foo, 2 AS bar").get_result(conn); downside I've tracked down to // the metadata returned by this api is not accessible from rust
let metadata = stmt.metadata(); // underlying delegate to `ffi::mysql_stmt_result_metadata`
// when trying to print fields of underlying raw pointer
println!("field_count: {}", (&unsafe { *result_ptr }).field_count); // this should be `2`, but `0` printed.
// when trying to print all fields via, segment faults with `(signal: 11, SIGSEGV: invalid memory reference)`
println!("fields: {:?}", metadata.fields()); by comparing pub struct st_mysql_res {
// uint64_t row_count;
pub row_count: my_ulonglong,
// MYSQL_FIELD *fields;
pub fields: *mut MYSQL_FIELD,
// struct MYSQL_DATA *data;
pub data: *mut MYSQL_DATA,
// MYSQL_ROWS *data_cursor;
pub data_cursor: *mut MYSQL_ROWS,
// unsigned long *lengths; /* column lengths of current row */
pub lengths: *mut ::std::os::raw::c_ulong,
// MYSQL *handle; /* for unbuffered reads */
pub handle: *mut MYSQL,
// const struct MYSQL_METHODS *methods;
pub methods: *const st_mysql_methods,
// MYSQL_ROW row; /* If unbuffered read */
pub row: MYSQL_ROW,
// MYSQL_ROW current_row; /* buffer to current row */
pub current_row: MYSQL_ROW,
// struct MEM_ROOT *field_alloc;
pub field_alloc: MEM_ROOT, // This field is embedded in rust
// unsigned int field_count, current_field;
pub field_count: ::std::os::raw::c_uint,
pub current_field: ::std::os::raw::c_uint,
// bool eof; /* Used by mysql_fetch_row */
pub eof: my_bool,
// bool unbuffered_fetch_cancelled;
pub unbuffered_fetch_cancelled: my_bool,
// enum enum_resultset_metadata metadata;
// void *extension;
pub extension: *mut ::std::os::raw::c_void,
} and corresponding C struct (from mysql typedef struct MYSQL_RES {
uint64_t row_count;
MYSQL_FIELD *fields;
struct MYSQL_DATA *data;
MYSQL_ROWS *data_cursor;
unsigned long *lengths; /* column lengths of current row */
MYSQL *handle; /* for unbuffered reads */
const struct MYSQL_METHODS *methods;
MYSQL_ROW row; /* If unbuffered read */
MYSQL_ROW current_row; /* buffer to current row */
// ------------------------
// NOTE here in C struct, the MEM_ROOT is a pointer
// ------------------------
struct MEM_ROOT *field_alloc;
unsigned int field_count, current_field;
bool eof; /* Used by mysql_fetch_row */
/* mysql_stmt_close() had to cancel this result */
bool unbuffered_fetch_cancelled;
// ------------------------
// NOTE here in C struct, a new field not in `st_mysql_res`
// ------------------------
enum enum_resultset_metadata metadata;
void *extension;
} MYSQL_RES; Note that the difference in alignment of diesel/diesel/src/mysql/connection/stmt/metadata.rs Lines 18 to 28 in a5c82df
But the difference (size) between pub struct st_mysql_field {
// char *name;
pub name: *mut ::std::os::raw::c_char,
// char *org_name;
pub org_name: *mut ::std::os::raw::c_char,
// char *table;
pub table: *mut ::std::os::raw::c_char,
// char *org_table;
pub org_table: *mut ::std::os::raw::c_char,
// char *db;
pub db: *mut ::std::os::raw::c_char,
// char *catalog;
pub catalog: *mut ::std::os::raw::c_char,
// /* THIS FIELD IS NOT PRESENT IN C STRUCT */
pub def: *mut ::std::os::raw::c_char,
// unsigned long length;
pub length: ::std::os::raw::c_ulong,
// unsigned long max_length;
pub max_length: ::std::os::raw::c_ulong,
// unsigned int name_length;
pub name_length: ::std::os::raw::c_uint,
// unsigned int org_name_length;
pub org_name_length: ::std::os::raw::c_uint,
// unsigned int table_length;
pub table_length: ::std::os::raw::c_uint,
// unsigned int org_table_length;
pub org_table_length: ::std::os::raw::c_uint,
// unsigned int db_length;
pub db_length: ::std::os::raw::c_uint,
// unsigned int catalog_length;
pub catalog_length: ::std::os::raw::c_uint,
// /* THIS FIELD IS NOT PRESENT IN C STRUCT */
pub def_length: ::std::os::raw::c_uint,
// unsigned int flags;
pub flags: ::std::os::raw::c_uint,
// unsigned int decimals;
pub decimals: ::std::os::raw::c_uint,
// unsigned int charsetnr;
pub charsetnr: ::std::os::raw::c_uint,
// enum enum_field_types type;
pub type_: enum_field_types,
// void *extension;
pub extension: *mut ::std::os::raw::c_void,
} I still can't see how specifying |
Maybe we should updating bindings for mysqlclient-sys, sgrif/mysqlclient-sys#24, |
@clouds56 Thanks for investigating. That's really helpful ❤️ I've marked this as release blocker now, as we should resolve this before issuing a new release. Given the current state of the mysqlclient-sys crate I would expect that this is unfortunately a bit more work than "just" updating the bindings. I'm generally not a big fan of only generating the bindings at build time as that requires a dependency on bindgen, which in turn requires libclang, which might be problematic on windows. (Help by all of this is appreciated.) |
Hi Apple fans, Thanks for @clouds56 investigation. mysql 8.0.1 Remove my_bool and then added And I also use rust-bindgen to autogen the Thanks, |
@xiangzhai Thanks for looking into this. This is likely a good starting point, but I fear it won't be as easy as just adjusting the code to work with the new version (only) as we also need to support older versions. I'm not sure yet how to do that. As for auto generating the bindings: I would consider accepting a PR to |
Hi @weiznich You are welcome! I am considering about LIBMYSQL_VERSION and MYSQL_VERSION_ID to get the
I just wrapper the my_bool and mysql_ssl_mode because there is no mysql_ssl_mode for MariaDB. Then it is able to still use
But there is ugly FALSE to support
Could you review the path to give some comments please? Thanks, |
Thanks, |
Setup
diesel_cli
Versions
Feature Flags
Problem Description
When running any commands using the
diesel
command, the error below is given:Its worth noting that
diesel setup
does create the database, but fails to run any migrations.What are you trying to accomplish?
Running migrations
What is the expected output?
Migrations that run? Not sure what else to put here
What is the actual output?
Are you seeing any additional errors?
No
Steps to reproduce
Repo: https://github.com/watsom27/diesel_bug
Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: