mongoserver disposable

68 views
Skip to first unread message

Grégoire Seux

unread,
Feb 28, 2012, 2:55:49 AM2/28/12
to mongodb...@googlegroups.com
Hello,

I would like to know why is the MongoServer not disposable. IMO one whould like to close all connections after having done some operations to mongodb. 
The method Disconnect has a strange comment : " Normally there is no need to call this method", why ?

Can you enlight me ?

Regards,

Greg

Robert Stam

unread,
Feb 28, 2012, 9:32:54 AM2/28/12
to mongodb...@googlegroups.com
The driver maintains a connection pool and handles opening and closing connections as necessary.

The only reason to call MongoServer.Disconnect is if you know you won't be doing any more MongoDB calls and would like to close all connections immediately. Otherwise the connections will be closed when your program exits.

Melocotonero

unread,
Feb 28, 2012, 2:52:16 PM2/28/12
to mongodb-csharp
But, in what kind of situations the driver assumes that the program
has exit? Because I have seen lots an lots of opened and closed
connections but my program is a webservice, it never ends.

Is there some kind of time out? Or even better, is there a way to not
close the connections until the webservice disposes or something like
that?

Thanks a lot!

On 28 feb, 15:32, Robert Stam <rob...@10gen.com> wrote:
> The driver maintains a connection pool and handles opening and closing
> connections as necessary.
>
> The only reason to call MongoServer.Disconnect is if you know you won't be
> doing any more MongoDB calls and would like to close all connections
> immediately. Otherwise the connections will be closed when your program
> exits.
>

Robert Stam

unread,
Feb 28, 2012, 3:08:38 PM2/28/12
to mongodb...@googlegroups.com
When the program exits the operating system closes all open connections (sockets). The C# driver is not involved in this case.

The C# driver closes a connection (socket) in any of these conditions:

1. An error has occurred on the connection (so the state of the connection is unknown)
2. A connection reaches maxConnectionIdelTime (default 10 minutes)
3. A connection reaches maxConnectionLifeTime (default 30 minutes)
4. The application calls MongoServer.Disconnect (which closes all the connections in the connection pool)

Do you have closed connections that can't be explained by any of the above?

Melocotonero

unread,
Feb 28, 2012, 3:21:47 PM2/28/12
to mongodb-csharp
I think that the second and third case are the explanation, I will
dive into the code to ensure it. But probably, that's it.

Thanks, now at least I have an explanation :)
Reply all
Reply to author
Forward
0 new messages