pgnotify icon indicating copy to clipboard operation
pgnotify copied to clipboard

not re-using connections

Open jayjacksonworks opened this issue 4 years ago • 2 comments

I think I'm noticing when I leave the listener on for an extended period of time, it creates multiple connections over time instead of re-using the same connection over and over. It behaves nicely for a bit but at some point, the number of connections skyrockets and it locks up my dev/test database. Was wondering if you should add some checks inside await_pg_notifications to see if the connection is stale/invalid before reconnecting.

Screen Shot 2021-03-22 at 10 42 56 PM Screen Shot 2021-03-22 at 10 42 45 PM

jayjacksonworks avatar Apr 02 '21 04:04 jayjacksonworks

Thanks for filing this issue!

In the interests of narrowing down the cause, are you able to share a sanitized snippet of the code you're using to create the connection?

djrobstep avatar Apr 03 '21 23:04 djrobstep

I was originally passing in a connecting string into the await_notifications but changed it to create the connection instance outside of my functions call, and then pass it in. I am now testing this to see if any improvements.

for notification in await_pg_notifications( "postgres://%s:%s@%s:%s/%s" % ( os.getenv("DB_USERNAME"), os.getenv("DB_PASSWORD"), os.getenv("DB_HOST"), os.getenv("DB_PORT"), os.getenv("DB_DATABASE") ), ['on_useractivity'], handle_signals=SIGNALS_TO_HANDLE):

On Apr 3, 2021, at 7:32 PM, djrobstep @.***> wrote:

Thanks for filing this issue!

In the interests of narrowing down the cause, are you able to share a sanitized snippet of the code you're using to create the connection?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/djrobstep/pgnotify/issues/5#issuecomment-812940782, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDNFB7JRATLHLKSXNKZSKLTG6JQVANCNFSM42IIPMXA.

jayjacksonworks avatar Apr 05 '21 01:04 jayjacksonworks