Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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
reused.
  • Loading branch information...
commit 7686d02cb0b844626d6a401e58c0755ef3bc8432 1 parent d417100
@isaacs isaacs authored
Showing with 6 additions and 0 deletions.
  1. +6 −0 lib/request.js
View
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) {
Please sign in to comment.
Something went wrong with that request. Please try again.