atheken/NoRM — Issue #86: Network error when reconnecting to database.
Author: rowland
Created: 2011-12-15 17:59:54+00:00
State: open

After connecting to and disconnecting from a database and a period of inactivity, reconnecting triggers this error:

System.ObjectDisposedException: Cannot access a disposed object.
at System.Net.Sockets.TcpClient.GetStream()
at Norm.Connection.GetStream() in x:\dev.net\lib\NoRM\NoRM\Connections\Connection.cs:line 133
at Norm.Connection.Write(Byte[] bytes, Int32 start, Int32 size) in x:\dev.net\lib\NoRM\NoRM\Connections\Connection.cs:line 164
at Norm.Protocol.Messages.QueryMessage`2.Execute() in x:\dev.net\lib\NoRM\NoRM\Protocol\Messages\QueryMessageGeneric.cs:line 100
at Norm.MongoQueryExecutor`2.d__0.MoveNext() in x:\dev.net\lib\NoRM\NoRM\MongoQueryExecutor.cs:line 57
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Norm.Collections.MongoCollection`1.FindOne[U](U template) in x:\dev.net\lib\NoRM\NoRM\Collections\MongoCollectionGeneric.cs:line 214

I suspect a network connection remained after "disconnecting" due to connection pooling being enabled, but the connection was likely severed by our firewall due to inactivity. Upon "reconnecting," the first request triggers the error above.

Unfortunately, disabling connection pooling leads to nasty errors much earlier and without the periods of inactivity.

I upgraded NoRM to the latest because I spotted an update awhile back that looks like it might solve this issue, but apparently that's not the case.