Am 28.08.2018 um 09:57 schrieb Ivo:

On Sun, 29 Jul 2018 10:57:12 +0200, Sönke Ludwig wrote:

So generally ConnectionPool assumes that each connection manages their
connection state individually, most importantly that it ensures that the
connection stays open/gets reconnected. Similarly, closing a connection
would also need to happen through the connection itself.

In the case of MongoClient, the code needs to be extended to enable
access to MongoConnection.disconnect() in some way, or to define a
closing logic within MongoConnection itself, for example a timeout.
The connection object itself would then still stay alive, but all
associated resources would be freed until it is used again. At that
point it would automatically reconnect.

Do you have specific semantics in mind for closing the connection(s)?

What I needed was simply to disconnect manually when required so that one can logout and login on MongoDB.
So my quick fix of the code was introducing a disconnect() method in the MongoClient class.
Here is the code:

void disconnect(){
	foreach (con ; m_connections.m_connections) {
		con.disconnect();
	}
}

I'm not sure at all this is enough to free all resources used by the connection pool, nevertheless I've been using it for a bit and it seems fine.

There is a PR now that officially adds MongoClient.cleanupConnections,
which does the same, except that it also checks for any connections that
are still locked: https://github.com/vibe-d/vibe.d/pull/2287