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

Random PostgreSQL connection errors #556

Open
amureki opened this issue Jan 12, 2024 · 10 comments
Open

Random PostgreSQL connection errors #556

amureki opened this issue Jan 12, 2024 · 10 comments

Comments

@amureki
Copy link

amureki commented Jan 12, 2024

Python Version

3.12

Django Version

4.2.9

Package Version

6.6.0

Description

Greetings dear fellows!

We are experiencing a lot of “InterfaceError: connection already closed” and “TransactionManagementError”. They are not necessarily accompany each other, but both are consistently happening.
PG logs are not showing anything unexpected or suspicious, but Django closing the connections.

Affected endpoints are different, and I see no common behaviour in them. For example, it sometimes fails even in the basic non-customized admin interface during GET requests.
It does not happen locally.

We did post more details in the following thread:
https://forum.djangoproject.com/t/interfaceerror-and-transactionmanagementerror-postgresql/16924

Later I noticed other people were sharing the similar issues:

And one recent comment was about suspecting a WhiteNoise upgrade.

We did downgrade WhiteNoise version from 6.6.0 to 5.3.0 (one major version) and it indeed resolved all mentioned issues on our instances.

I am struggling to pin the issue down to the change, but happy to assist and provide any other details.

Best,
Rust

@adamchainz
Copy link
Collaborator

I don’t think I can really do anything without more details or a reproducing sample project. I have used the latest whitenoise versions with PostgreSQL just fine.

If you could try git bisect, or at least manual bisecting beteeen the two versions you found, that would help narrow down the probable cause. But again without a reproduction it’s hard to write a fix.

@adamchainz
Copy link
Collaborator

If you want to hire me as a consultant I could work directly within your project to tackle the issue. I’m not entirely conviver it’s due to whitenoise, as this package does not touch the database at all.

@amureki
Copy link
Author

amureki commented Jan 15, 2024

I don’t think I can really do anything without more details or a reproducing sample project. I have used the latest whitenoise versions with PostgreSQL just fine.

I agree, it is quite a vague issue that I submitted, but I am struggling to reproduce it to be able to pin it down to certain functionality or commit and share an example project.
As soon as I'll have something, I will surely post it.

Thank you for the response and help proposal! I'll check with my company if we can organize something. ✨

Cheers,
Rust

@lapinvert
Copy link

I had same issue for months, it was driving me crazy. Luckily I found the djangoproject thread where someone pointed out whitenoise.

Downgrading to 5.3.0 solved the issue for me as well. Thank you @amureki .

It is concerning tho because many ppl may be actually impacted. The only reason I was able to notice and I guess other ppl in the threads as well, is because I use sentry. If you don't and I suspect most people don't, you just end up with weird things happening in your database, states that were not supposed to happen, without knowing what's going on.

If most users of 6.6.0 have no issues, it maybe a combination of things that cause the issue, maybe it would be nice @amureki if we got to chat a bit and see what our apps had in common besides whitenoise.

@kgrinberg
Copy link

I don't want to overpromise, but I do expect that in the coming weeks we'll be able to carve out some time here to bisect and hopefully diagnose the problem (which we did find was solved in the immediate case by downgrading from 6.6.0 to 5.3.0). Gun to my head I'd say it's something in the middleware (possibly in combination with others etc) but I'll report what we find.

@dustinblanchard
Copy link

I'm having the same problem. I'm on Python 3.12 and Django 4.2.8 and soon to upgrade to 5, @amureki @kgrinberg @lapinvert did y'all have any compatibility issues with 5.3.0 and current python/django versions?

@kgrinberg
Copy link

I've only tested with LTS Django (so 3.2.x and 4.2.x) so can't comment on Django 5 and this issue. To reiterate, I do suspect it's something more subtle/complicated than "these things just don't work together", but hope to have something more concrete to share when we've had some time here to delve in, which likely won't be for a couple weeks.

@breadmaking
Copy link

breadmaking commented Feb 4, 2024

Also had the same issue recently with a cookiecutter project - there was no pattern to where it would occur. All across my app in production. Identical symptoms to @amureki

Running on:
django ==4.2.9
whitenoise==6.6.0
Downgrading to 5.3.0 solved the issue for me as well.

That said I have another cookiecutter project running in production with no issues at all:
django==4.0.10
whitenoise==6.3.0

@brianjp93
Copy link

Downgrading to 5.3.0 seems to have fixed the errors for me as well. Was on django==4.2.9 and whitenoise==6.6.0 like the others in this thread. Python 3.11.7

@Block99block99
Copy link

Same here with
django==4.2.11
whitenoise==6.6.0

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

8 participants