Vercel blocks Convex connection to database

I built next.js app with Convex database. There I worked just fine for few days, but now connection to database is, I think, blocked by Vercel’s firewall or something like that. I tried to use other hostings and self-hosted it and website is working, but on Vercel I am just getting error from Convex’s http client, that doesn’t really tell anything

Error: 
    at (node_modules/convex/dist/esm/browser/http_client.js:183:0)
    at (src/middleware.ts:29:20)
    at (node_modules/next/dist/esm/server/web/adapter.js:158:0)

but connection is refused because it throws that error in here:

if (!response.ok && response.status !== STATUS_CODE_UDF_FAILED) {
   throw new Error(await response.text());
}

I have no idea what happened, because as I telled before it worked fine for few days.

Hey @ang33l. Do the runtime logs have any more error details?

Another thing to check is that all of your environment variables related to the database connection are still valid. Sometimes a connection problem is caused by an expired token, for example.

It returns only that error I added at the beginning.

Funny thing, I’ve implemented it also on netlify and I am testing on both vercel and it and it looks like main problem is in the middleware.

When I am trying to fetch data from convex inside of middleware, it throws that error (but only on Vercel).

//middleware.ts
import { api } from "../convex/_generated/api";
import {  fetchQuery } from "convex/nextjs";
...
        const response = await fetchQuery(api.antyhing);

if I remove middleware file, application will work fine but without validating all paths I want to check with it.

I can’t belive it. Didn’t change anything, redeployed app and it didn’t work as before. After few minutes it started to work. I don’t know what is going on.
I see 1 corelation, that last time app on Vercel worked was 24hrs ago. Is it possible that it exhausted some daily limit for requests or something like that?

1 Like

I’m glad it’s working now! Unfortunately, I don’t have enough info here to say for sure what was causing the problem. There are a couple of possibilities I can think of.

It’s possible that requests from your Vercel deployment were rate limited. That would have been from Convex rather than from Vercel. You can find some info about limits on the Convex Pricing page, and you should be able to get more info from them if you reach out to the Convex team directly: Convex Community

Another possibility is a connection timeout if it was taking longer than maximum execution duration (currently 25 seconds) to begin sending a response.

Update: I did some more digging and found this post about a similar issue where the Convex folks have responded that they released a fix about half an hour ago. I think that’s why it’s suddenly working for you. :smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.