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

MySQL, error in my_thread_global_end #79

Open
unreg opened this issue Feb 23, 2017 · 6 comments
Open

MySQL, error in my_thread_global_end #79

unreg opened this issue Feb 23, 2017 · 6 comments

Comments

@unreg
Copy link

unreg commented Feb 23, 2017

Hi! I have some problem.
I use on linux system:

  • unixODBC-2.3.4;
  • mysql-5.6.35;
  • myodbc-5.2.7;
  • python-3.6.0;
  • pyodbc-4.0.11;
  • aioodbc-0.0.3.

For any query I get an error message, not exception:

Error in my_thread_global_end(): 2 threads didn't exit

Query is executed correctly, only error message on console.

Code is very simple, from example, with pool and without pool:

dsn = f'Driver=myodbc;User={USER};Password={PASSWORD};Database={DB};'

async with aioodbc.create_pool(dsn=dsn, loop=loop) as pool:
    async with pool.acquire() as conn:
        async with conn.cursor() as cur:
            await cur.execute('SHOW TABLES;')
            val = await cur.fetchone()

Same code with just pyodbc runs without error message:

import pyodbc

cnxn = pyodbc.connect(dsn)
cursor = cnxn.cursor()
cursor.execute('SHOW TABLES;')
r = cursor.fetchall()

MySQL settings is default. Why can this error message?

@jettify
Copy link
Member

jettify commented Feb 26, 2017

I saw this logs, my best guess is that problem somewhere in mysql odbc library.

Code in your example is not equivalent, since async context managers also explicitly close cursor and connections in connection pool, when in your case connection and cursor destroyed with gc or exit of interpreter.

@jettify
Copy link
Member

jettify commented Feb 26, 2017

Same code used for postgresql and sqlite without any issue.

@jettify
Copy link
Member

jettify commented Feb 26, 2017

Found related MySQL issue https://bugs.mysql.com/bug.php?id=64466 , aioodbc may open connection in one thread and close it in other, MySQL driver does not like this, other odbc dbs work pretty fine this way.

@unreg
Copy link
Author

unreg commented Feb 26, 2017

my best guess is that problem somewhere in mysql odbc library.

may open connection in one thread and close it in other, MySQL driver does not like this

likely to...

@jettify
Copy link
Member

jettify commented Feb 26, 2017

Can confirm opening connection in one thread and closing it in other is root cause, not sure what I can do about this, since it is more ODBC MySQL driver issue, other dbs work as expected.

Possible solution is custom implementation of TheadPoolExecutor that can route blocking code depending to proper worker using threa_id information.

@jettify
Copy link
Member

jettify commented Feb 26, 2017

Probably this should not be an issue for MySQL >= 5.7.9 since mysql_thread_end [1] is no longer required to be called in [2].

[1] https://dev.mysql.com/doc/refman/5.7/en/mysql-thread-end.html
[2] https://github.com/mysql/mysql-connector-odbc/blob/4f6159d8dde269d9f90ccb74d239f047ed5ad3a3/driver/handle.c#L368-L375

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

No branches or pull requests

2 participants