繁体   English   中英

C# mongo db 驱动程序随机无法连接到数据库

[英]C# mongo db driver randomly cannot connect to db

我有控制台应用程序,它通过 C# mongo 驱动程序在单独的线程中调用 mongo db。 连接池限制为10,连接字符串为:mongodb+srv://login:pass@address/test?retryWrites=true&w=majority&connect=replicaSet

在我启动控制台应用程序的一半时间里,它会在 30 秒超时后下降。 当我重新启动应用程序时,它会以 50% 的概率正常工作。 如果第一个操作失败 - 任何其他操作也会失败。 如果第一个没问题,其他任何一个都可以正常工作。

例外:

MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }。 集群状态的客户端视图是 { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [], DnsMonitorException : "DnsClient.DnsResponseException: Unhandled exception ---> System .IndexOutOfRangeException:无法读取字节 277,超出范围。在 DnsClient.DnsDatagramReader.ReadByte() 在 DnsClient.DnsDatagramReader.ReadLabels() 在 DnsClient.DnsDatagramReader.ReadQuestionQueryString() 在 DnsClient.DnsRecordFactory.ReadRecordInfo() 在 DnsClientResponseDnsMessage (ArraySegment 1 responseData) at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout) at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection 1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit) --- End of inner异常堆栈跟踪 --- 在 DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection 1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit) at DnsClient.LookupClient.QueryInternal(IReadOnlyCollection 1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit) at DnsClient.LookupClient.QueryInternal(IReadOnlyCollection 1 servers, DnsQuestion question, Boolean useCache) at DnsClient.LookupClient.Query(String query, QueryType queryType, QueryClass queryClass) at MongoDB.Driver.Core.Misc。 MongoDB.Driver.Core.Clusters.DnsMonitor.Monitor() 处的 DnsClientWrapper.ResolveSrvRecords(String service, CancellationToken cancellingToken)" }.)'

此异常最初是在此调用堆栈中引发的:MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector, MongoDB.Driver.Core.Clusters.ClusterDescription) MongoDB.Driver.Core。 Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(System.Threading.Tasks.Task) MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedAsync(MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector, MongoDB.Driver.Core.Clusters.ClusterDescription, System.Threading.Tasks.Task, System.TimeSpan, System.Threading.CancellationToken) System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) MongoDB.Driver .Core.Clusters.Cluster.SelectServerAsync(MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector, System.Threading.CancellationToken) System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.Compiler Services.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) ... [调用堆栈被截断]

内:

使用 CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } } 选择服务器 30000 毫秒后发生超时。 集群状态的客户端视图是 { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [], DnsMonitorException : "DnsClient.DnsResponseException: Unhandled exception ---> System .IndexOutOfRangeException:无法读取字节 277,超出范围。在 DnsClient.DnsDatagramReader.ReadByte() 在 DnsClient.DnsDatagramReader.ReadLabels() 在 DnsClient.DnsDatagramReader.ReadQuestionQueryString() 在 DnsClient.DnsRecordFactory.ReadRecordInfo() 在 DnsClientResponseDnsMessage (ArraySegment 1 responseData) at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout) at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection 1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit) --- End of inner异常堆栈跟踪 --- 在 DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection 1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit) at DnsClient.LookupClient.QueryInternal(IReadOnlyCollection 1 servers, DnsMessageHandler handler, DnsRequestMessage request, Boolean useCache, LookupClientAudit continueAudit) at DnsClient.LookupClient.QueryInternal(IReadOnlyCollection 1 servers, DnsQuestion question, Boolean useCache) at DnsClient.LookupClient.Query(String query, QueryType queryType, QueryClass queryClass) at MongoDB.Driver.Core.Misc。 MongoDB.Driver.Core.Clusters.DnsMonitor.Monitor() 中的 DnsClientWrapper.ResolveSrvRecords(String service, CancellationToken cancellingToken)"}。

我问了我们的 NodeJS 开发人员,他回答说他没有这样的问题。 有人遇到过这个问题吗?

我也得到了最后一天的确切错误。 我不确定确切的问题,但这肯定与我使用的网络有关。 我通过将我的开发机器连接到我手机的热点进行了测试,它工作正常。 但是当我再次切换到宽带连接时,它失败了。

希望它可以帮助某人。

我还提出了一个关于 mongodb 支持的错误。 这是链接

编辑:

最终通过将“ DnsClient ”nuget 包升级到 1.3.0 版来修复它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM