-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Multiple Local API queries in hooks will never resolve (Postgres) #6743
Comments
Hey @lekterable — I just reproduced this with your exact code and I can't seem to reproduce. In order to help here, we're going to need you to provide a minimal reproduction - but I'd be happy to help once we can understand how to reproduce! |
huh, okay that's very strange, because the only thing that helped me was changing the adapter to Mongo so you're able to query twice in the same hooks execution from the Postgres db? @jmikrut I'll prepare a repro when I have a moment |
Yep. I did two consecutive finds in the same Are you setting max connections or anything like that? One thing you could try is to pass the Every time you do a
So your code as-is will start 3 different transactions (one for the main create / update op, and one each for your find ops). If you pass the Try that? |
Not explicitly, I'm using the default settings which Railway provides. I only copied the
Thanks for the tip! I think I'll just stick to Mongo as it seems to be more matured and doesn't cause any issues, but I'll try to provide a full repro when I have a minute. |
Of course. It's worth noting that MongoDB would have this same issue if you use MongoDB with replica sets (you need replica sets in order to get MongoDB to work with transactions). This would explain why in MongoDB, you do not see any issues (you probably don't have replica sets, so transactions are not enabled). This whole transactions topic is a database-wide paradigm, in that transactions operate by reserving a connection for a specific transaction. Doesn't matter if it's Postgres or MongoDB - both work the same way when enabled. I do think that for most use cases, Payload lends itself well to MongoDB though. So if you can switch, I wouldn't stop ya! If you do get around to getting a repro put together, please post it here and I will re-open the issue. Thank you! |
I have the same issue, but am not sure how to reproduce exactly. In hooks I was able to fix by adding Here's an example repository https://github.com/christopherpickering/idle_in_transaction
In my code, I have around 12 larger pages. Here's the onInit that fails in my code: import { locales } from '../locales'
export const preloadSearch = async ({ payload }): Promise<void> => {
const sync =[{ collection: 'products'}, {collection: 'pages'}
]
// in this example, this works.... but if you add more pages, around 12 in my app,
// the query takes longer and this leaves behind some idle in transactions.
// sync.map(c => {
// Promise.all(locales.locales.map(l => preload({ payload, sync: c, locale: l.code })))
// })
// this fixes the problem
sync.map(c => {
Promise.all(locales.locales.map((l, index) => {
setTimeout(function () {
preload({ payload, sync: c, locale: l.code })
}, index * 1000);
}))
})
}
export const preload = async ({ payload, sync, locale }): Promise<void> => {
console.log(sync, locale)
let r = await payload.find({
req: {payload},
collection: sync.collection,
depth: 1,
limit: 10000,
locale: locale,
pagination: false,
})
} |
In this particular case, the other thing that seems to fix the problem for me (lots of queries running at the same time) is increasing the max connection limit on the pool from 10 to 50. db: postgresAdapter({
pool: {
connectionString: process.env.DATABASE_URI,
max:50
},
}), I tried to follow it back through /node_modules/drizzle-orm/node-postgres/session.cjs, and it seems like on line 127 |
This issue has been automatically locked. |
Link to reproduction
No response
Describe the Bug
Running more than one Local API query in hooks will never resolve.
I originally reported it on Discord here, but I never got a response.
After playing with it a little bit more it seems that it's a Postgres specific issue as after changing the db to Mongo it doesn't happen anymore.
Looks like a pretty big limitation for the Postgres adapter.
The above example will never get to the
console.log('after')
line while using Postgres, it does work on Mongo though.To Reproduce
.find
in my case)Payload Version
2.19.3
Adapters and Plugins
db-postgres
The text was updated successfully, but these errors were encountered: