"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
P
Percy40d ago
Project ID: f740c960-4ea5-4e0d-a8fc-7b3efef00d50
J
JohnC40d 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
B
Brody40d ago
going to need more info, what kind of app is this?
J
JohnC40d 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.
B
Brody40d ago
is your app using different database clients for the different parts of the app?
J
JohnC40d ago
Do you mean is the database that I have been using that is on your platform providing everything I just mentioned?
B
Brody40d ago
for the record, i dont work for railway, so it would not be my platform
J
JohnC40d ago
Sorry lol I just assumed My mistake
B
Brody40d ago
not what i mean, does your app use different database clients for the different parts of the app?
J
JohnC40d ago
No I see people complain about psycop2. Could that be the issue?
B
Brody40d ago
the issue is that your database client is trying to use closed connections
J
JohnC40d 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?
B
Brody40d ago
make sure the client isnt trying to use a closed connection
J
JohnC40d 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
B
Brody40d ago
i have not
J
JohnC40d 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
B
Brody40d 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
J
JohnC40d ago
Thanks. By the way, I appreciate you taking the time to interact with me even though you do not work for Railway
B
Brody40d 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.
J
JohnC40d ago
👍
Want results from more Discord servers?
Add your server
More Posts
Unable to update Variables in App. (First Update after Migration)Hey Guys, my App tries to connect to the old containers of my postgres and redis. I checked the variImage Storagehello everyone, can I use Postgresql to store the images which my users upload in django-project?Setup Cloudflare Proxy1. Clicked "custom domain". 2. Railway pops up a CNAME for me to add to Cloudflare. 3. Add CNAME recDirectus: impossible to update or to run the old versionProject ID : 9be34f5b-fa35-49c1-83c5-f0fbd245db9b Template : https://github.com/kadumedim/directus-sCSV files in storage/app/data/csv not accessible?Hello, I've setup a laravel api on railway. I have a seeder that tries to load csv files from the I have not touched my project in several weeks but at midnight railway reverted to a very old versioI'm very confused it looks like my project was deployed last night, although I have not touched it iI can't add DNS from GoDaddy to RailwayThey recommend me to change the server name...Unable to connect database after payentHello, i just pay for the month, now i'm unable to connect to the database. please help1,2GB RAM usage in React APPDo you know if it's normal this size of ram in a frontend created with react and typescript?Shopify proxy and HTTP/1.0Hello, I need help from members using Railway to host a Shopify app. I ran into this problem where Is it possible to change the default config of a Mysql Container?By default the container uses up a minimum of 500mb of ram, I found a stack overflow post on how to Cannot link, login nor logout with cli>railway logout 🚨 Response not successful status=404 >railway login 🚨 Response not successful staLost 2FA code for my accountI have lost my 2FA authenticator codes and I would like to reset my accountHow does it work the HD allocationI need 360gb to use how much does it cost?how to restore postgres db from dumb?i was given my db archives because my db was deleted due to migration. I am trying to restore the dbActivate SSL on my custom domainHello, I bought the domain apocolinks.com at DreamHost.com, this domain already has an active SSL ceBest way to secure postgres?What would be the best way to secure my postgres instance from outside connections? I would just turdeployments "Crashed"Hello, good afternoon, my problem is: deployments "Crashed" and the information in deploy logs MessaHow to use railway with monorepo?I created a new project and essentially my server code is not at the top level, and instead is one dHow can i set a limit?How can i set a limit per month?