SOLVED - (psycopg2.OperationalError) SSL connection has been closed unexpectedly

If anyone get’s this error in their python alchemy app then know that this fixes it:

engine = create_engine(DB_URL, pool_pre_ping=True, pool_recycle=300)

Pre ping filters out dead connections that were hitting my system and causing havok

What’s interesting is that this question was asked before. And the staff instructed the user to take the conversation private and then locked the thread after 30 days.

I want to urge the staff to change their policy on the 30-day forum comment lockout. The status quo has the potential to generate a lot of long term negative value by producing a series of user problems into the forum that ultimately go unanswered. I wanted to come in and answer the question in this thread above… But the thread is locked!

It turns out that sqlalchemy’s default connection pooling is the nail gun of developer foot guns. It’s also infrequent and never triggers after a fresh app re-deploy, since non of the connections in the pool have had a chance to expire. I’m also guessing that this pattern is EXTREMELY common in python apps using a database. Really, the sqlalchmey devs should have chosen to use a NullPool by default since a connection pool is really a later stage optimization setting, but it is what it is.

I’m sure bugs of this scale exists in other tech stacks. And because of things like docker, can’t force a fix on it’s developers. So right now, the forum either here on’s or stack overflow (or similar) is where developers using will go. So please, until a question is answered, don’t close it off! 30 days is certainly too little of time.

Thanks for everything you guys do. is truly awesome!!

I’d like to note that we are not manually closing threads after 30 days, that is a forum software (Discourse) setting. The closure is automatic.

Is this something you can change?

I’m new here to Render, and I’ve never been in a position to administrate Discourse until now. I believe it can be changed, I don’t think we plan on changing it.

This is an interesting example of a gnarly ecosystem specific issue, similar to a weird interaction involving NextJS that we in Support are aware of. I have been seeing an uptick of these “SSL connection has been closed unexpectedly” errors too and haven’t been sure what to make of it.

We appreciate your assistance with this issue, we can (and undoubtedly will) offer it up as a possible solution to other customers, and will see if engineering can make use of it to as a means of understanding and possibly resolving dead connections making a mess in the first place.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.