R
Railwayβ€’8mo ago
JohnC

"Error: connection already closed."

I keep getting this error message when I attempt to update a user in my PostgreSQL database. I do not have such errors when users are interacting with the web application which also utilizes the database throughout use of the application. I tried wrapping the update in try exception block with 10 retries and I even close unused connections every hour
20 Replies
Percy
Percyβ€’8mo ago
Project ID: f740c960-4ea5-4e0d-a8fc-7b3efef00d50
JohnC
JohnCβ€’8mo ago
f740c960-4ea5-4e0d-a8fc-7b3efef00d50 I used to get an error SSL SYSCALL error: EOF detectedError but now it just states connection already closed
Brody
Brodyβ€’8mo ago
going to need more info, what kind of app is this?
JohnC
JohnCβ€’8mo ago
I have a Django backend application that is deployed on your platform that interacts with a postgreSQL database on your platform as well. I have Django handling the backend and React handling the frontend. It is a SPA application that offers user authorization, interaction with forms where the user enters a numerical set and that set is used to create a matrix and then deconstructed into a set of numerical sets and then displayed to the user on the frontend. Each time a user enters a set the backend/frontend updates (decrements a daily entry count). There are several pages that are injected via React router. I have not had any issues with this part of the application. However, when a standard user navigates to the payment page and makes a purchase using the Stripe API, the transactions go through and the webhook executes after a successful payment ( I have no issues there either). The webhook uses an apScheduler to setup a cron job 30 seconds after a successful payment, and it is during this time that causes the error. So the cron job executes 30 seconds after the webhook finishes execution. In this function the user is accessed via stripe_checkout_id (foreign-key) and then updated in the user_table (changes from standard user to whatever membership was purchased) and updates entry fields as well. It is only during this process that I see the error. I am sorry if I am being to Verbose. What does not make sense is that I am able to update the users during their sessions in the database while interacting with the frontend (decrementing available entries). But as soon as a payment is made and I go to update the user so they have these features I get an error that connection is closed.
Brody
Brodyβ€’8mo ago
is your app using different database clients for the different parts of the app?
JohnC
JohnCβ€’8mo ago
Do you mean is the database that I have been using that is on your platform providing everything I just mentioned?
Brody
Brodyβ€’8mo ago
for the record, i dont work for railway, so it would not be my platform
JohnC
JohnCβ€’8mo ago
Sorry lol I just assumed My mistake
Brody
Brodyβ€’8mo ago
not what i mean, does your app use different database clients for the different parts of the app?
JohnC
JohnCβ€’8mo ago
No I see people complain about psycop2. Could that be the issue?
Brody
Brodyβ€’8mo ago
the issue is that your database client is trying to use closed connections
JohnC
JohnCβ€’8mo ago
I read on a thread that closing unused connections every hour worked for them. Unfortunately it is not working for me Do you have any suggestions?
Brody
Brodyβ€’8mo ago
make sure the client isnt trying to use a closed connection
JohnC
JohnCβ€’8mo ago
By the way I am new to full stack development and I appreciate your patience. I just graduated last may and built the entire application from scratch so... Have you worked with Django
Brody
Brodyβ€’8mo ago
i have not
JohnC
JohnCβ€’8mo ago
So here is the info from the Django documentation. The default value is 0 , preserving the historical behavior of closing the database connection at the end of each request. To enable persistent connections, set CONN_MAX_AGE to a positive integer of seconds. For unlimited persistent connections, set it to None . So maybe I should change the settings... What you do think? Or what would you suggest
Brody
Brodyβ€’8mo ago
it is clear from the information that you provided that database connections are not being fully closed, the client tries to use a closed connection and that is where the error is coming from
JohnC
JohnCβ€’8mo ago
Thanks. By the way, I appreciate you taking the time to interact with me even though you do not work for Railway
Brody
Brodyβ€’8mo ago
happy to help where I can. while I unfortunately can't give you a direct solution, I can at minimum tell you where the problem originates from.
JohnC
JohnCβ€’8mo ago
πŸ‘
Want results from more Discord servers?
Add your server