Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request pending forever if content type is application/json

See original GitHub issue

Problem/Feature Request Summary

Not able to parse request body when the header is application/json

Environment Information

  • koa-body: 4.1.0
  • Koa: 2.7.0
  • Node.js: 12.4.0
  • koa-router: 7.4.0

Current Behavior

When request Content-Type header is application/json the request stay pending forever resolving. ,

Steps to Reproduce

const Router = require(“koa-router”); const koaBody = require(“koa-body”)

Expected Behavior

application/json content parsed

Context (Environment)

For urlencoded or text request its working fine.

I tried to debug it and I can see the options passed to the co-body json are:

   encoding: 'utf-8', 
   limit: '1mb',
   strict: true,
   returnRawBody: false

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

ozziexshcommented, Aug 6, 2019

I can confirm we’re experiencing this as well, but I should note that this only happens when we deploy to Google Cloud Functions, running locally works fine.

Reproducing this is pretty simple:

const koa = require("koa");
const koaBody = require("koa-body");
const KoaRouter = require("koa-router");

const app = new koa();

app.use(koaBody({ multipart: true }));

const router = new KoaRouter();"/", ctx => {
  ctx.body = ctx.request.body;


if (process.env.NODE_ENV !== "production") {

exports.callback = app.callback();

In postman if you enable the header Content-Type: application/json it hangs forever, but if you take it out then it responds immediately.

ozziexshcommented, Aug 6, 2019

Decided to spend some time and dig into this and was able to replicate it on the functions emulator.

Looks to be an issue with the ctx.req stream already being “read” and the raw-body dep doesn’t handle that, see here:

Not sure what the solution is here though to actually get koa-body access to that data though…

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Patch request is forever stuck on pending
On triggering the event that leads to the request on the front end; My network has two items : A preflight with status...
Read more >
chrome requests get stuck pending - nginx - Server Fault
If it's stuck waiting for the end of the content, it means the web server fully received and processed the request, you should...
Read more >
Pending Client Certificate List REST Service - IBM
The processing of the request fails because of an unexpected condition on the server. Content-Type, application/json. Content-Language, Locale for the response ...
Read more >
Request stuck in pending state / promise never resolves #941
If I add logs in the "response" callback and the requestPromise.then() , I'll see both of them, indicating that the promise created by...
Read more >
How to Cancel Pending API Requests to Show Correct Data
One problem quickly became evident: if the user clicked around fast enough, as previous network requests got resolved, the UI was updated ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found