Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created March 3, 2015 00:04
Show Gist options
  • Save isaacs/926587b40c07cb32e9fa to your computer and use it in GitHub Desktop.
Save isaacs/926587b40c07cb32e9fa to your computer and use it in GitHub Desktop.
From 6765c58a27f9a9ef4a7820e10259e464d9fbbb33 Mon Sep 17 00:00:00 2001
From: isaacs <i@izs.me>
Date: Mon, 2 Mar 2015 16:03:34 -0800
Subject: [PATCH] http: do not reuse socket on error responses
Some servers (in this case, CouchDB) behave very oddly when you attempt
to re-use a socket that returned an error response.
---
lib/_http_client.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 5e722b4..9a37f5b 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -391,6 +391,10 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
req.shouldKeepAlive = false;
}
+ // some servers are weird about re-using sockets that had HTTP errors.
+ if (res.statusCode > 399) {
+ req.shouldKeepAlive = false;
+ }
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
LTTNG_HTTP_CLIENT_RESPONSE(socket, req);
--
2.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment