summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-17 23:59:39 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-17 23:59:39 +0000
commitfbd6d792accf142ef6ad188b0fd9ac09d370d80a (patch)
tree667e72cae77620a495decc34acf882da8f855247 /net
parent8df2d1f8dde16442af61f6203acdf03ce4dc8879 (diff)
downloadchromium_src-fbd6d792accf142ef6ad188b0fd9ac09d370d80a.zip
chromium_src-fbd6d792accf142ef6ad188b0fd9ac09d370d80a.tar.gz
chromium_src-fbd6d792accf142ef6ad188b0fd9ac09d370d80a.tar.bz2
Add CHECKs to keep the socket counts in sync.
A full chromebot run on 189.0 revealed them getting out of sync, so this should reveal where they get out of sync. BUG=http://crbug.com/14395. Review URL: http://codereview.chromium.org/125276 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/tcp_client_socket_pool.cc38
-rw-r--r--net/base/tcp_client_socket_pool.h7
2 files changed, 42 insertions, 3 deletions
diff --git a/net/base/tcp_client_socket_pool.cc b/net/base/tcp_client_socket_pool.cc
index 969ad3d..da2d04b9 100644
--- a/net/base/tcp_client_socket_pool.cc
+++ b/net/base/tcp_client_socket_pool.cc
@@ -165,6 +165,8 @@ int ClientSocketPoolBase::RequestSocket(
DCHECK_GE(priority, 0);
Group& group = group_map_[group_name];
+ CheckSocketCounts(group);
+
// Can we make another active socket now?
if (group.active_socket_count == max_sockets_per_group_) {
CHECK(callback);
@@ -184,6 +186,8 @@ int ClientSocketPoolBase::RequestSocket(
// We found one we can reuse!
handle->set_socket(idle_socket.socket);
handle->set_is_reused(true);
+ group.sockets_handed_out_count++;
+ CheckSocketCounts(group);
return OK;
}
delete idle_socket.socket;
@@ -194,7 +198,7 @@ int ClientSocketPoolBase::RequestSocket(
CHECK(callback);
Request r(handle, callback, priority, resolve_info,
LOAD_STATE_RESOLVING_HOST);
- group_map_[group_name].connecting_requests[handle] = r;
+ group.connecting_requests[handle] = r;
CHECK(!ContainsKey(connecting_socket_map_, handle));
@@ -203,6 +207,8 @@ int ClientSocketPoolBase::RequestSocket(
client_socket_factory_, this);
connecting_socket_map_[handle] = connecting_socket;
int rv = connecting_socket->Connect();
+
+ CheckSocketCounts(group);
return rv;
}
@@ -212,6 +218,8 @@ void ClientSocketPoolBase::CancelRequest(const std::string& group_name,
Group& group = group_map_[group_name];
+ CheckSocketCounts(group);
+
// Search pending_requests for matching handle.
RequestQueue::iterator it = group.pending_requests.begin();
for (; it != group.pending_requests.end(); ++it) {
@@ -236,8 +244,11 @@ void ClientSocketPoolBase::CancelRequest(const std::string& group_name,
CHECK(group.pending_requests.empty());
CHECK(group.connecting_requests.empty());
group_map_.erase(group_name);
+ return;
}
}
+
+ CheckSocketCounts(group);
}
void ClientSocketPoolBase::ReleaseSocket(const std::string& group_name,
@@ -356,7 +367,10 @@ void ClientSocketPoolBase::DoReleaseSocket(const std::string& group_name,
Group& group = i->second;
CHECK(group.active_socket_count > 0);
+ CheckSocketCounts(group);
+
group.active_socket_count--;
+ group.sockets_handed_out_count--;
const bool can_reuse = socket->IsConnectedAndIdle();
if (can_reuse) {
@@ -377,6 +391,9 @@ void ClientSocketPoolBase::DoReleaseSocket(const std::string& group_name,
int rv = RequestSocket(
group_name, r.resolve_info, r.priority, r.handle, r.callback);
+
+ CheckSocketCounts(group);
+
if (rv != ERR_IO_PENDING)
r.callback->Run(rv);
return;
@@ -387,6 +404,8 @@ void ClientSocketPoolBase::DoReleaseSocket(const std::string& group_name,
CHECK(group.pending_requests.empty());
CHECK(group.connecting_requests.empty());
group_map_.erase(i);
+ } else {
+ CheckSocketCounts(group);
}
}
@@ -416,6 +435,8 @@ CompletionCallback* ClientSocketPoolBase::OnConnectingRequestComplete(
CHECK(group_it != group_map_.end());
Group& group = group_it->second;
+ CheckSocketCounts(group);
+
RequestMap* request_map = &group.connecting_requests;
RequestMap::iterator it = request_map->find(handle);
@@ -432,10 +453,15 @@ CompletionCallback* ClientSocketPoolBase::OnConnectingRequestComplete(
DCHECK(group.pending_requests.empty());
DCHECK(group.connecting_requests.empty());
group_map_.erase(group_name);
+ } else {
+ CheckSocketCounts(group);
}
} else {
request.handle->set_socket(socket);
request.handle->set_is_reused(false);
+ group.sockets_handed_out_count++;
+
+ CheckSocketCounts(group);
}
RemoveConnectingSocket(request.handle);
@@ -443,6 +469,16 @@ CompletionCallback* ClientSocketPoolBase::OnConnectingRequestComplete(
return request.callback;
}
+// static
+void ClientSocketPoolBase::CheckSocketCounts(const Group& group) {
+ CHECK(group.active_socket_count ==
+ group.sockets_handed_out_count +
+ static_cast<int>(group.connecting_requests.size()))
+ << "[active_socket_count: " << group.active_socket_count
+ << " ] [sockets_handed_out_count: " << group.sockets_handed_out_count
+ << " ] [connecting_requests size: " << group.connecting_requests.size();
+}
+
void ClientSocketPoolBase::RemoveConnectingSocket(
const ClientSocketHandle* handle) {
ConnectingSocketMap::iterator it = connecting_socket_map_.find(handle);
diff --git a/net/base/tcp_client_socket_pool.h b/net/base/tcp_client_socket_pool.h
index 1e18b2e..377457b 100644
--- a/net/base/tcp_client_socket_pool.h
+++ b/net/base/tcp_client_socket_pool.h
@@ -172,11 +172,12 @@ class ClientSocketPoolBase : public base::RefCounted<ClientSocketPoolBase> {
// A Group is allocated per group_name when there are idle sockets or pending
// requests. Otherwise, the Group object is removed from the map.
struct Group {
- Group() : active_socket_count(0) {}
+ Group() : active_socket_count(0), sockets_handed_out_count(0) {}
std::deque<IdleSocket> idle_sockets;
RequestQueue pending_requests;
RequestMap connecting_requests;
- int active_socket_count;
+ int active_socket_count; // number of active sockets
+ int sockets_handed_out_count; // number of sockets given to clients
};
typedef std::map<std::string, Group> GroupMap;
@@ -208,6 +209,8 @@ class ClientSocketPoolBase : public base::RefCounted<ClientSocketPoolBase> {
// |connecting_socket_map_|.
void RemoveConnectingSocket(const ClientSocketHandle* handle);
+ static void CheckSocketCounts(const Group& group);
+
ClientSocketFactory* const client_socket_factory_;
GroupMap group_map_;