Next.js Discord

Discord Forum

How to resolve this error `Couldn't connect to compute node` & `Connection terminated unexpectedly`

Unanswered
.oxyzen posted this in #help-forum
Open in Discord
Avatar
Hi, I hope you guys are doing well. I've been working with Vercel Postgres and encountered this error. Can anyone help me with this?
Image

7 Replies

Avatar
Greater Flamingo
Hi @.oxyzen were you able to get this fixed? I'm having the same problem. It seems to come from Neon after a cold start
Avatar
Gazami crab
I also need help with this, and that is correct it seems to only happen on cold starts. I don't think this has to do with hot module reload on local env, its also happening deployed in vercel
Avatar
Gazami crab
From neon error docs.
Image
Avatar
Greater Flamingo
@Gazami crab I managed to find a not very pretty workaround basically by doing retries 1s apart each other until it succeeds or it reaches the maximum retry. I've noticed that it only takes a couple of secs max to warm up the db so this works

Here's a snippet:

const retryQuery = async (
  retries = 3
): Promise<DailyBenchmark[]> => {
  try {
    return await query();
  } catch (err) {
    if (retries === 0) throw err;

    await sleep(1000);
    return await retryQuery(retries - 1);
  }
};
If you find something better, please share it 🙂 I'll be also looking for a better solution. This sounds like an issue with Vercel and Neon though but I may be wrong
Avatar
I don't know if this count as a fix but I'm running the local dev server with --turbo flag. This works for me and didn't throw any error till now.
Avatar
Greater Flamingo
It should be fixed guys 🙂
Image