Weird timeout on Cloudflare Workers
Hi. I was playing around with drizzle and the neon serverless driver over WebSockets and got an issue.
When deployed to Cloudflare Workers using Vercel and Next, the first request passes and the second request timeouts 100% of the times. When deployed to Lambda, it always works.
Here is the code: https://github.com/achaconm2001/neon-pool
There are 2 routes:
/ => Main Page (edge)
/test => Route (edge)
/2 => Main Page (lambda)
/test2 => Route (lambda)
GitHub
GitHub - achaconm2001/neon-pool
Contribute to achaconm2001/neon-pool development by creating an account on GitHub.
12 Replies
reduced-jadeOP•2y ago
Note: I didn't use the ws constructor because it causes weird errors. It seems to work fine without the ws constructor
It seems every even request timeouts (on edge)
reduced-jadeOP•2y ago
Neon
Neon serverless driver - Neon Docs
The Neon serverless driver is a low latency Postgres driver for JavaScript and TypeScript that allows you to query data from serverless and edge environments over HTTP or WebSockets in place of TCP. T...
reduced-jadeOP•2y ago
Okay, I was able to fix the timeout issue with this code
Note 1: Every time I use the drizzle object, it creates a new Pool and returns it
Note 2: I never call pool.close()
Currently, it works, but may be I introduced a connection or memory leak
I accept suggestions and comments :3
foreign-sapphire•2y ago
Hey, this does look leaky. I'd need to look into the code a little more later.
reduced-jadeOP•2y ago
GitHub
GitHub - achaconm2001/neon-pool
Contribute to achaconm2001/neon-pool development by creating an account on GitHub.
reduced-jadeOP•2y ago
I was exploring with the new using api from typescript 5.2
This will end the pool when the connection object goes out of scope
It still have to create a new pool instance for all scopes where the db is used
I'm still looking for a cleaner solution if you have anything in mind
genetic-orange•2y ago
@Gary, el Pingüino Artefacto what about
reduced-jadeOP•2y ago
This will cause the timeout of the even requests again
Will work on Lambda but not ok Cloudflare Workers
reduced-jadeOP•2y ago
Neon
Neon serverless driver - Neon Docs
The Neon serverless driver is a low latency Postgres driver for JavaScript and TypeScript that allows you to query data from serverless and edge environments over HTTP or WebSockets in place of TCP. T...
reduced-jadeOP•2y ago
may be creating a new pool for each scope isn't that bad as I think, I did some benchmarks and the creation of the Pool is (almost) under < 1ms
foreign-sapphire•2y ago
Did you achieve something? @Gary, el Pingüino Artefacto @ShinyPokemon @schmime
I must know if this causes a memory leak or drain my connection pool @Gary, el Pingüino Artefacto @ShinyPokemon @schmime
reduced-jadeOP•2y ago
you can test it yourself, i put all the code on git