vercel / micro

Asynchronous HTTP microservices
MIT License
10.59k stars 459 forks source link

await buffer(req) hangs forever, doesn't finish #485

Closed AndrewRayCode closed 9 months ago

AndrewRayCode commented 9 months ago

In a Stripe webhook in Next.js api route src/pages/api/webhooks/stripe.ts

import { buffer } from 'micro';

const action = async (req: NextApiRequest, res: NextApiResponse) => {
  console.log('raw body', req.body);
  const body = await buffer(req);
  console.log('parsed body', body);
}

This hangs forever with both micro 9.4.0 and 10.0.0. Using Nextjs 13.4.2.

Sample console output:

raw body { id: '...', object: 'event', api_version: '2020-08-27', created: 1707460102, data: { object: { ... } } type: 'product.updated' }

As you can see, req.body is populated, but the parsed body line is never logged. The webhook callback hangs from Stripe and eventually times out.

Failed to POST: Post "http://localhost:3030/api/webhooks/stripe": context deadline exceeded

AndrewRayCode commented 9 months ago

I must have been doing something else wrong, because this is working for me now. I don't have an idea of what I changed to resolve this issue. But I am no longer seeing the await hang forever.