Problem with first connection to database
Hi i created cront task app in js and i use prisma in in to save some data and log to database, and i have problem with first connection to database,
i set my app to retry tast so i know that when i run same task second time it works fine without error...
i added to my connection string
?schema=public&connect_timeout=30&pool_timeout=30&socket_timeout=30
and on app first run i added
and this is my prisma.js
![No description](https://cdn.answeroverflow.com/1232724096240975976/image.png)
Solution:Jump to solution
```js
if (updatedProductsData.length !== 0) {
for (let product of updatedProductsData) {
promises.push(
prisma.Product.updateMany({...
11 Replies
I think it is not able to fetch the db creds
from the env
but only on first try of task?
in logs i have info when cron start (SyncStock...)
on error in abort it
and retry
and on retry it is working
can you check if it is connecting to the database
in 1 min it will retry this task so i will show it
okay
it can be that that, the connection is not happening for that particular file or execution
you might have to check if the prisma instance is accessible for hat file.
![No description](https://cdn.answeroverflow.com/1232727716814651392/image.png)
i restated app with 30s task timer
on first run error, on retry its working
on test with 15m timer it error 2 times so
its like connection to bd is to long and it close it
and when its short time bt connections it works on second try
first connection to DB is too long? and it auto close it when nothing happend for too long?
you can try something like this
And also check if the db url has required parameters for the connection like keepAlive etc.
I think that might help.
k thx, i will try
ok i had stupid bug (my fault)
Solution
... I forgot
await
before prisma
...
It's funny that it was only on prod that this error occurred, and locally I tested it a million times and never had this error xd
so thx, and can be closed ; )