inngest-js
inngest-js copied to clipboard
Syncing inngest app in Remix using Single Fetch throws an error
Describe the bug If using the new Single Fetch function, calling the endpoint where inngest is located with PUT, it throws the following error:
Unhandled error in Remix request
module: "remix"
err: {
"type": "SyntaxError",
"message": "Failed calling `body` from serve handler when checking body for request signing as method is PUT; Unexpected end of JSON input",
"stack":
SyntaxError: Failed calling `body` from serve handler when checking body for request signing as method is PUT; Unexpected end of JSON input
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)
at successSteps (node:internal/deps/undici/undici:5555:27)
at fullyReadBody (node:internal/deps/undici/undici:1665:9)
at async specConsumeBody (node:internal/deps/undici/undici:5564:7)
at async Promise.all (index 2)
at InngestHandler (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/src/components/InngestCommHandler.ts:755:41)
at async Object.callRouteAction (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected][email protected]/node_modules/@remix-run/server-runtime/dist/data.js:36:16)
at <anonymous> (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:4899:19)
at callLoaderOrAction (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:4963:16)
at async Promise.all (index 0)
at defaultDataStrategy (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:4772:17)
at callDataStrategyImpl (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:4835:17)
at callDataStrategy (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:3992:19)
at submit (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:3755:21)
at queryImpl (/Users/agustin/Developer/personal/afippi/node_modules/.pnpm/@[email protected]/node_modules/@remix-run/router/router.ts:3684:22)
To Reproduce Steps to reproduce the behavior:
- Start your application
- Run
curl -X PUT http://localhost:3000/api/inngest
System info
- OS: macOS
- Node version: 20
- Inngest version: 3.23.1
@jpwilliams Any updates on this?
Also seeing this in Next.js 14.2.18 w/ Inngest 3.31.11.
also seeing this in [email protected]
I was hitting this on Next.js too and it bugged me enough that I decide to debug it. I think I know what's going on.
The first thing I noticed was that if I change my code from
export const { GET, POST, PUT } = serve({
client: inngest,
functions: [ ... ],
});
to
const inngestHandlers = serve({
client: inngest,
functions: [ ... ],
});
export const POST = (...args: Parameters<typeof inngestHandlers.POST>) => {
if (args[0].body === null) {
console.log('Saw a POST request with no body. Ignoring it.')
return
}
return inngestHandlers.POST(...args);
}
export const GET = (...args: Parameters<typeof inngestHandlers.GET>) => {
if (args[0].body === null) {
console.log('Saw a GET request with no body. Ignoring it.')
return
}
return inngestHandlers.GET(...args);
}
export const PUT = (...args: Parameters<typeof inngestHandlers.PUT>) => {
if (args[0].body === null) {
console.log('Saw a PUT request with no body. Ignoring it.')
return
}
return inngestHandlers.PUT(...args);
}
then I can avoid the warning. It's weird that the body of the incoming request was null. I don't show it in the code above, but I also checked the headers and the incoming request had a 40 character content length and a content-type of JSON.
For me, the error only happens on the first request to the server and that request is particularly slow. My hunch was that the request was getting terminated by the Inngest server before next.js had a chance to process it and so the body was getting set as null.
I tracked down what the timeout associated with the Inngest server -> app value was an it is 10 seconds. I have a lot of functions, so my code was taking more than 10 seconds to compile. Could be the explanation. I hacked my server to have fewer functions and when my compile time was 5 seconds then the error went away. I'm pretty sure that's the explanation.
I can see a couple possible solutions:
- Allow the timeout value in Inngest server to be configurable so that in a dev server the number can be made much higher
- Update the Inngest app side client to better handle the null body case. It's current behavior isn't horrible, but at least the error message could be improved so that other people don't spend time trying to figure out what's going on
- Next.js could be updated to avoid calling the PUT handler if the request is canceled before the compiling finishes. I think this is the most valuable fix because it's a widespread improvement.
I think 1 is the only solution that would avoid a warning message entirely. I think 3 has the most chance of saving the community time debugging unexpected behavior.