my worker is throwing too many, error 1101.
I am migrating from Lambda, I was using this code
but in case of my worker, one request works & the other does not, not sure what's wrong here.
10 Replies
I traced it down to my db, this file exactely, something is not right here.
well what do the logs say?
it executes fine for the first couple of times and then throws this error.
I tried migrating to a D1 db and still the same error.
something is wrong with the global context somehow ..
doing this directly inside my route handler works
however moving the db init to the global context breaks
no sorry
I have this code living in a monorepo package
that makes it break.
unfortunately I am still facing this issue.
is there something wrong with exporting connections from the global scope like so ?
utils/db.ts
could it be because of "pg" ?
@Walshy ideas ?
it's weird cuz 1 request works another doesn't.
it's not because of
pg
moving the db connection to the route and destroying it in the route. works perfectly.
this works
but this doesn't
You should avoid you doing stuff like DB connections in the global scope. It is not really good for setting stuff like that up
should I init a new db connection per request, can't I cache the connection somehow to reuse it between requests ?
You could use hyperdrive which makes a pool
yeah, I am looking how to use it right now. thanks.
how does this look ?
same issue thou when I try to cache the connection
db