Retry requests on reused sockets that receive ERR_EMPTY_RESPONSE.

We retry requests on ERR_CONNECTION_CLOSED in case of a close/reuse race, but
ERR_CONNECTION_CLOSED is converted to ERR_EMPTY_RESPONSE if this is a socket's
first request. Such a socket is normally not reused unless it was a preconnect
miss.

To avoid test flakiness, make the UNUSED vs UNUSED_IDLE determination not
timing-sensitive. The existing logic is compares idle_time to 0, so it's
dependent on clock granularity rather than any intentional timeout.

Add equivalent tests to HttpNetworkTransactionTest.KeepAliveConnection for
preconnect misses.

BUG=352156

Review URL: https://codereview.chromium.org/197283012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257748 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 4c6be63c..ba27cb7 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -1443,7 +1443,11 @@
     // likely happen when trying to retrieve its IP address.
     // See http://crbug.com/105824 for more details.
     case ERR_SOCKET_NOT_CONNECTED:
-      if (ShouldResendRequest(error)) {
+    // If a socket is closed on its initial request, HttpStreamParser returns
+    // ERR_EMPTY_RESPONSE. This may still be close/reuse race if the socket was
+    // preconnected but failed to be used before the server timed it out.
+    case ERR_EMPTY_RESPONSE:
+      if (ShouldResendRequest()) {
         net_log_.AddEventWithNetErrorCode(
             NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
         ResetConnectionAndRequestForResend();
@@ -1494,7 +1498,7 @@
   return response_.headers.get();
 }
 
-bool HttpNetworkTransaction::ShouldResendRequest(int error) const {
+bool HttpNetworkTransaction::ShouldResendRequest() const {
   bool connection_is_proven = stream_->IsConnectionReused();
   bool has_received_headers = GetResponseHeaders() != NULL;