Nextjs tRPC POST Requests Hang with Cloudflare DNS Proxy Enabled
duantranhuy
PROOP

8 months ago

ProjectID: 7d98cee2-4752-43e0-9546-7593b2de0068

Environment Details

  • Project Type: Next.js application with tRPC

  • tRPC Version: v11

  • Cloudflare Configuration: Full protection with DNS proxy enabled

Problem Description

When using Cloudflare with DNS proxy enabled (orange cloud), tRPC mutation requests (POST) hang indefinitely, while query requests (GET) continue to work successfully. It is fine with local and my vps server but fail in railway.

Technical Details

  • Working: All tRPC query operations that use GET requests

  • Not Working: All tRPC mutation operations that use POST requests (create, update, delete)

  • Behavior: Requests hang without timing out or returning errors

Code Configuration

Our tRPC client is configured with standard HTTP batch links:

httpBatchLink({
  transformer: SuperJSON,
  url: getBaseUrl() + "/api/trpc",
  headers: () => {
    const headers = new Headers();
    headers.set("x-trpc-source", "nextjs-react");
    return headers;
  },
})

Our API route handler uses the standard fetch handler:

const handler = (req: NextRequest) =>
  fetchRequestHandler({
    endpoint: "/api/trpc",
    req,
    router: appRouter,
    createContext: () => createContext(req),
    onError: // error handling
  });

export { handler as GET, handler as POST };
Solved

0 Replies

brody
EMPLOYEE

8 months ago

Hello,

What happens when you call the Railway service domain directly?


duantranhuy
PROOP

8 months ago

Hi


brody
EMPLOYEE

8 months ago

Pressed enter too soon 😅


duantranhuy
PROOP

8 months ago

it is the same error.


brody
EMPLOYEE

8 months ago

Do the tRPC requests done with POST expect HTTP/2?


duantranhuy
PROOP

8 months ago

No it doesn't


brody
EMPLOYEE

8 months ago

Well there goes that theory of Railway's HTTP/1.1 only nature being an issue


brody
EMPLOYEE

8 months ago

For the current deployment there are two 499 status code, and two stream errors in your deploy logs, perhaps those will give you a clue as to the issue?


brody
EMPLOYEE

8 months ago

And I just noticed this is Bun, as the saying goes, if I had a dollar for every time bun was at fault for a networking issue


duantranhuy
PROOP

8 months ago

yes 499 and two stream errors is issue


duantranhuy
PROOP

8 months ago

let me change to use yarn is it ok?


duantranhuy
PROOP

8 months ago

but this container setup work on my vps ^^


brody
EMPLOYEE

8 months ago

I'm assuming you are using bun as a runtime here, not just the package manager?


duantranhuy
PROOP

8 months ago

let me change to yarn and use node


brody
EMPLOYEE

8 months ago

Bun might not like being behind a Proxy, might not like being in a container environment, Bun's slim image may have problems, it really could be any manner of things


brody
EMPLOYEE

8 months ago

Sounds good, please keep me updated!


duantranhuy
PROOP

8 months ago

Thank you. It was bun issue.


duantranhuy
PROOP

8 months ago

I hope I knew this sooner.


duantranhuy
PROOP

8 months ago

Can I use static IP for domain from cloudflare


brody
EMPLOYEE

8 months ago

No unfortunately, we don't support static inbound IPs yet


brody
EMPLOYEE

8 months ago

!s


Status changed to Solved brody 9 months ago


Loading...