-1

My Application works perfectly fine untill I send multiple (2 or more) request simultaneously. As soon as I send multiple requests Express throws

Error: Can't set headers after they are sent.

Its a long code, where its takes almost 2 seconds to execute complete request . If I send multiple requests (where response time is pretty fast) i dont face this issue?

I know the reason why and when express throws 'Can't set headers' error. My main point is to understand how I can debug my application in this scenario as everything works fine incase of single request and it breaks down incase of multiple requests.

Alex
  • 1,406
  • 2
  • 18
  • 33
  • 6
    Please share some code. What have you done till now ? – Ateev Chopra Apr 04 '16 at 11:34
  • Its a long code, where its takes almost 1 - 1.5 seconds to execute complete request . If i send multiple request (where response time is pretty fast) i dont face this issue? – Alex Apr 04 '16 at 11:41
  • 1
    this might be helpful http://stackoverflow.com/questions/7042340/node-js-error-cant-set-headers-after-they-are-sent – FastTurtle Apr 04 '16 at 11:41

1 Answers1

0

The error means that you're already in the Body but later in the code some function tried to set a header or statusCode. When you see this error, try to look the code for any improper callbacks or exception scenarios in which the response object is referenced multiple times. Usually it must be next() called twice .

Jibin TJ
  • 416
  • 1
  • 4
  • 15