Socket Hangup when connecting to Neon from node (Drizzle ORM)
Hello, I recently switched to Neon - I'm building a serverless Remix app using Drizzle as an ORM. I'm able to use neon successfully, but my coworker is unable to connect due to a socket hangup issue. Has anyone else ran into this issue?
13 Replies
inc-lavender•2y ago
Are they behind a proxy? IIRC it means the server is not sending a response, but I can't see why Neon would send you a response, but not your coworker
eastern-cyanOP•2y ago
Let me check! And ill have them try connecting directly using psql as well
genetic-orange•2y ago
Oops 😬 turns out I was using Node v21.x.x, the issue resolved itself once changing to v18.x.x!
inc-lavender•2y ago
Interesting. Do you have a stack trace? Was it an issue with Neon's serverless driver in Node 21.x? Would be good to open an issue in GitHub if so!
absent-sapphire•7mo ago
Hmm, I'm also getting this error now when I try to send 2 DB requests sequentially. The first one always succeeds and on the second request I get this:
rare-sapphire•7mo ago
@Conrad Ludgate any ideas?
fascinating-indigo•7mo ago
I'm afraid not. It could be any number of things but if it's consistent then it's likely a fault with the serverless setup somewhere (the serverless host/nodejs version).
absent-sapphire•7mo ago
So yesterday I think I tracked down the issue to be related to TypeScript circular imports in my project. I'm not exactly sure how that could interrupt the DB connection, but it seemed to be causing it. Would it be useful if I created a reproducible example repo on GitHub?
rare-sapphire•7mo ago
Yes, a reproduceable example would be great 🙏
absent-sapphire•7mo ago
No worries!
absent-sapphire•7mo ago
Ok update I located the issue. It was happening because I was importing the Shopify app remix adapter for Vercel at the root level of my app:
import '@shopify/shopify-app-remix/adapters/vercel';
The source code for this adapter fiddles with the fetch implementation and this appears to have been causing the socket hangups:
https://github.com/Shopify/shopify-app-js/blob/main/packages/apps/shopify-app-remix/src/server/adapters/vercel/index.tsGitHub
shopify-app-js/packages/apps/shopify-app-remix/src/server/adapters/...
Contribute to Shopify/shopify-app-js development by creating an account on GitHub.
absent-sapphire•7mo ago
Although the issue still happens even if I configure neon to use node-fetch instead of global fetch like so:
Anyone have any ideas?
provincial-silver•7mo ago
@Jake
Can you share if the hang issue is still persistent after using https://github.com/neondatabase/examples/blob/main/with-nextjs-drizzle-edge/lib/drizzle.server.ts ?