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

Worker sometimes loose connection and needs to be restarted with psycopg2 #559

Open
Jeanbouvatt opened this issue Nov 17, 2022 · 2 comments

Comments

@Jeanbouvatt
Copy link

Similar to #216 , My worker sometimes loose the connection and must be restarted

[...]
cursor = self.connection.cursor()
psycopg2.InterfaceError: connection already closed

My env :

python==3.8.13
Django==3.2.16
django-rq==2.6.0
psycopg2==2.9.5
redis==4.4.0rc4
rq==1.11.1
@Jeanbouvatt
Copy link
Author

Jeanbouvatt commented Nov 22, 2022

calling django.db.close_old_connections at the beginning of all our task solved our problem in production, however our test suit ceased to work in CI/CD, probably because our test suit is run with ASYNC_QUEUES=False.

My solution was to patch django.db.close_old_connections in test suit so it does not trigger.

Annoying though.

@Jeanbouvatt
Copy link
Author

it seems the connection is lost when a Django database exception occurs.

A simple example:

def task():
  User.objects.get(id=non_existent_id) # Obviously fails
except Exception:
  User.objects.all().delete() # This will raise another exception : connection is closed

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

1 participant