Skip to content
Browse files

Destroy connection on 5xx errors

When there's a keepalive connection, it can cause the client to continue
to make requests to a server that is having a Bad Time, and even prevent
that server from being taken out of rotation appropriately.

When we get a 5xx error, destroy the socket right away so that it is not
  • Loading branch information...
1 parent d417100 commit 7686d02cb0b844626d6a401e58c0755ef3bc8432 @isaacs isaacs committed Mar 29, 2014
Showing with 6 additions and 0 deletions.
  1. +6 −0 lib/request.js
6 lib/request.js
@@ -189,6 +189,12 @@ function decodeResponseBody(cb) {
return function (er, response, data) {
if (er) return cb(er, response, data)
+ // don't ever re-use connections that had server errors.
+ // those sockets connect to the Bad Place!
+ if (response.socket && response.statusCode > 500) {
+ response.socket.destroy()
+ }
if (response.headers['content-encoding'] !== 'gzip') return cb(er, response, data)
zlib.gunzip(data, function (er, buf) {

0 comments on commit 7686d02

Please sign in to comment.
Something went wrong with that request. Please try again.