mcfunley / pugsql

A HugSQL-inspired database library for Python
https://pugsql.org
Apache License 2.0
673 stars 22 forks source link

Is an explicit disconnect required? #49

Open hanckmann opened 3 years ago

hanckmann commented 3 years ago

After running a script using pugsql, the following error messages are (always) in my database logs:

2021-01-01T05:50:02.596129Z 177181 [Note] Aborted connection 177181 to db: 'pmx' user: 'devv' host: '127.0.0.1' (Got timeout reading communication packets)
2021-01-01T08:05:02.745313Z 178061 [Note] Aborted connection 178061 to db: 'pmx' user: 'devv' host: '127.0.0.1' (Got timeout reading communication packets)
2021-01-01T10:36:29.269940Z 179043 [Note] Aborted connection 179043 to db: 'pme' user: 'devv' host: '23.143.154.21' (Got timeout reading communication packets)
2021-01-01T10:50:02.680148Z 179134 [Note] Aborted connection 179134 to db: 'pmx' user: 'devv' host: '127.0.0.1' (Got timeout reading communication packets)

This error might occur when a connection is not properly closed. Should i execute explicit disconnects? If yes, than I could not find this in the documentation.

The database in use is MySQL.

Kind regards

ggregoire commented 2 years ago

I was wondering too but the method disconnect doesn't actually disconnect anything.

php-coder commented 1 year ago

I have the same question. Any updates on this?

PeterSanctus commented 1 year ago

I had the same problem, when one queries the DataBase to check active connections, it can be seen that the connections is gathering there, and not really being closed. So I get a lot of problems of too many conns.

What I did was in Module->disconnect, I change the code to dispose the sqlAlchemy engine first:

def disconnect(self):
        """
        Disassociates the module from any connection it was previously given.
        """
        self.engine.engine.dispose()
        self.engine = None
        self._sessionmaker = None