diff options
author | Rahul Sundararaman <rahul.sundararaman@10gen.com> | 2019-06-07 15:52:51 -0400 |
---|---|---|
committer | Rahul Sundararaman <rahul.sundararaman@10gen.com> | 2019-06-07 15:52:51 -0400 |
commit | 1cb17cca8d2cff0888a83adcdd7f9ceedc237dad (patch) | |
tree | f93b256333592b7b4f1625e3c2b7cdf456f487e7 | |
parent | 9e73aceada701e0bf9fbd4730898ce21f68a9801 (diff) | |
download | mongo-1cb17cca8d2cff0888a83adcdd7f9ceedc237dad.tar.gz |
SERVER-39642 Decrement egress counter when scoped connection not returned to the pool backport
-rw-r--r-- | src/mongo/client/connpool.cpp | 11 | ||||
-rw-r--r-- | src/mongo/client/connpool.h | 6 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp index dc2678e655b..b8d49f668e4 100644 --- a/src/mongo/client/connpool.cpp +++ b/src/mongo/client/connpool.cpp @@ -336,6 +336,11 @@ void DBConnectionPool::release(const string& host, DBClientBase* c) { _pools[PoolKey(host, c->getSoTimeout())].done(this, c); } +void DBConnectionPool::decrementEgress(const string& host, DBClientBase* c) { + stdx::lock_guard<stdx::mutex> L(_mutex); + PoolForHost& p = _pools[PoolKey(host, c->getSoTimeout())]; + --p._checkedOut; +} DBConnectionPool::~DBConnectionPool() { // Do not log in destruction, because global connection pools get @@ -538,6 +543,12 @@ void ScopedDbConnection::done() { _conn = NULL; } +void ScopedDbConnection::kill() { + globalConnPool.decrementEgress(_host, _conn); + delete _conn; + _conn = NULL; +} + void ScopedDbConnection::_setSocketTimeout() { if (!_conn) return; diff --git a/src/mongo/client/connpool.h b/src/mongo/client/connpool.h index c3ad2b03a30..a10754c51b2 100644 --- a/src/mongo/client/connpool.h +++ b/src/mongo/client/connpool.h @@ -263,6 +263,7 @@ public: int getNumBadConns(const std::string& host, double socketTimeout = 0) const; void release(const std::string& host, DBClientBase* c); + void decrementEgress(const std::string& host, DBClientBase* c); void addHook(DBConnectionHook* hook); // we take ownership void appendConnectionStats(executor::ConnectionPoolStats* stats) const; @@ -415,10 +416,7 @@ public: /** Force closure of the connection. You should call this if you leave it in a bad state. Destructor will do this too, but it is verbose. */ - void kill() { - delete _conn; - _conn = 0; - } + void kill(); /** Call this when you are done with the connection. |