hi  -

*many* details are not here, database in use, driver, versions, etc.    Most 
people won't be able to help with a problem like this without basic details.

As it turns out I can tell you are using MySQL or MariaDB and the error is 
described at https://dev.mysql.com/doc/refman/5.7/en/communication-errors.html .

SQLAlchemy uses a connection pool, which is documented at 
https://docs.sqlalchemy.org/en/13/core/pooling.html .   so when you "close" a 
connection, it's usually just returned to the connection pool.    SQLAlchemy 
itself never just lets a connection fall away unless special steps are taken.   
However, if the Python process is killed, then all those connections will 
produce this error on the server.     Additionally, if the engine itself that 
you got from create_engine() is allowed to be garbage collected (which is not a 
normal pattern), that will cause this to happen also.    if you are disposing 
an engine (which usually you shouldn't, unless your application handles an 
arbitrary number of distinct URLs), you want to call dispose() on it.

This message can also occur if you are using a service like HAProxy to proxy 
connections, it will produce this error in the server log when it drops 
connections since it doesn't speak the MySQL protocol.

On Sun, Feb 28, 2021, at 9:45 AM, William Edwards wrote:
> Hello,
> 
> Since implementing SQLAlchemy, my logs have been filling up with 'Aborted 
> connection' messages.
> 
> --
> Aborted connection 294656 to db: 'unconnected' user: 'root' host: 'localhost' 
> (Got an error reading communication packets)
> --
> 
> However, according to the documentation, my code should make SQLAlchemy close 
> the connection neatly:
> 
> --
> with self.engine.engine.connect() as connection:
>     self.result = connection.execute(self.query)
> --
> 
> self.engine.engine is whatever 'sa.create_engine' returns.
> 
> Why are these connections kept open anyway?
> 
> Thank you.
> 

> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/f2107381-6e2b-4f2a-b28f-8b5c7eee8029n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/f2107381-6e2b-4f2a-b28f-8b5c7eee8029n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/010b1bd2-ad7f-44bc-9efd-98d5b342ba04%40www.fastmail.com.

Reply via email to