仅在特定项目下的 MongoDB 超时 [英] MongoDB timeout under specific project only

查看:106
本文介绍了仅在特定项目下的 MongoDB 超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个项目 (.sln),它们是他们自己的项目,外加一个包含 MongoDB 代码的辅助项目.

I have a 3 projects (.sln) that are their own project plus a secondary project that has the MongoDB code in it.

在同一台计算机上打开 3 个 Visual Studio 项目,调用相同的方法,其中只有 1 个可以工作,其他都抛出和错误.由于它是同一行代码,这意味着主项目中有一个 mongo 似乎不喜欢的设置.知道这可能是什么.

On the same computer with the 3 visual studio project open calling the same methods only 1 of them work the other all throw and error. Since it's the same line of code it mean there is a setting in the main project that mongo doesn't seems to like. Any idea what this might be.

这是 mongo 共享项目中的相关方法:

here's the method in question in the shared project for mongo:

public static class MongoTool
{
    public static bool DoesCollectionExist(string username, string password, string uri, string port, string database, string collectionName)
    {
        // get the client
        var client = new MongoClient($@"mongodb://{username}:{password}@{uri}:{port}");

        // get the database
        var db = client.GetDatabase(database);

        // create the filter for collection names
        var filter = new BsonDocument("name", collectionName);
        var options = new ListCollectionNamesOptions { Filter = filter };

        // return if the filter return at least 1 record
        return db.ListCollectionNames(options).Any();
    }
}

在一个虚拟控制台应用程序的项目之一中,我有以下调用并且它可以工作,它返回 true.

in one of the project a dummy console application i have the following call and it works, it returns true.

namespace ConsoleApp1781
{
    class Program
    {
        static void Main(string[] args)
        {
            var test = MongoTool.DoesCollectionExist("admin", "admin", "127.0.0.1", "27017", "SampleSet", "TemperatureProbe");
        }
    }   
}

在另一个项目 winform 应用程序中,我有这个代码(第三个项目使用类似但有相同的错误):

In another project winform app i have this code (the third project use similar but have same error) :

private void CustomMongoSaveTest(Probe temperatureProbe)
{
    if (Environment.UserName.Contains("tech"))
    {
        // check if collection exist
        var collectionExist = MongoTool.DoesCollectionExist("admin", "admin", "127.0.0.1", "27017", "SampleSet", "TemperatureProbe");

        // if the collection exists
        if (collectionExist)
        {
            // create the bson document
            var bsonDoc = MongoTool.ConvertToBsonDocument(temperatureProbe);

            // insert in collection
            MongoTool.SaveDocument(bsonDoc, "admin", "admin", "127.0.0.1", "27017", "SampleSet", "TemperatureProbe");
        }

    }
}

虽然是在同一台计算机上运行的完全相同的代码,但第二个抛出以下异常.将相同的项目附加到所有解决方案中,我可以轻松地按照代码进行操作,并且在线上发生异常:

Although being the same exact code running on the same computer that second one is throwing the following exception. Having the same project in attach to all solution i can easily follow the code and the exception occur on the line :

db.ListCollectionNames(options).Any();

除了:

使用 30000 毫秒选择服务器后发生超时CompositeServerSelector{ 选择器 =MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector,LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000} }.集群状态的客户端视图是 { ClusterId : 1", ConnectionMode:自动",类型:未知",状态:断开连接",服务器:[{ServerId:{ ClusterId:1,端点:"127.0.0.1:27017";}",端点:127.0.0.1:27017",ReasonChanged:ServerInitialDescription",状态:断开连接",服务器版本:,拓扑版本:,类型:未知",LastHeartbeatTimestamp: null, LastUpdateTimestamp:2020-08-07T16:00:54.4780565Z"}] }.

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "127.0.0.1:27017" }", EndPoint: "127.0.0.1:27017", ReasonChanged: "ServerInitialDescription", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", LastHeartbeatTimestamp: null, LastUpdateTimestamp: "2020-08-07T16:00:54.4780565Z" }] }.

在为不同的处理(如集合创建/删除)添加额外的方法后,除了在控制台应用程序中之外,没有任何工作.所有项目都使用nuget MongoDB.Driver 2.11.0

After adding extra methods for different handling like Collection Create/Delete, none of the works except when inside a console application. all project uses nuget MongoDB.Driver 2.11.0

当我运行该行时,我设法检查了日志文件中的差异,但它崩溃了,这就是 Mongo 日志中的差异:

I managed to check the difference in the log file when i run the line and it crash and this the difference in the Mongo logs :

{"t":{"$date":"2020-08-07T12:21:30.806-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn243","msg":"connection ended","attr":{"remote":"127.0.0.1:60792","connectionCount":5}}
{"t":{"$date":"2020-08-07T12:21:30.808-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn244","msg":"connection ended","attr":{"remote":"127.0.0.1:60793","connectionCount":4}}
{"t":{"$date":"2020-08-07T12:21:30.808-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn247","msg":"connection ended","attr":{"remote":"127.0.0.1:60796","connectionCount":3}}
{"t":{"$date":"2020-08-07T12:21:30.808-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn245","msg":"connection ended","attr":{"remote":"127.0.0.1:60794","connectionCount":2}}
{"t":{"$date":"2020-08-07T12:21:31.951-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn246","msg":"connection ended","attr":{"remote":"127.0.0.1:60795","connectionCount":1}}
{"t":{"$date":"2020-08-07T12:23:02.293-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn242","msg":"connection ended","attr":{"remote":"127.0.0.1:60791","connectionCount":0}}

当从运行日志的应用程序调用同一行时,我有这个:

When calling the same line form the app that works the log is different, i have this :

{"t":{"$date":"2020-08-07T12:31:02.088-04:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"connection accepted","attr":{"remote":"127.0.0.1:61402","sessionId":248,"connectionCount":1}}
{"t":{"$date":"2020-08-07T12:31:02.093-04:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"connection accepted","attr":{"remote":"127.0.0.1:61403","sessionId":249,"connectionCount":2}}
{"t":{"$date":"2020-08-07T12:31:02.136-04:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn249","msg":"client metadata","attr":{"remote":"127.0.0.1:61403","client":"conn249","doc":{"driver":{"name":"mongo-csharp-driver","version":"2.11.0.0"},"os":{"type":"Windows","name":"Microsoft Windows 10.0.18362","architecture":"x86_64","version":"10.0.18362"},"platform":".NET Framework 4.8.4180.0"}}}
{"t":{"$date":"2020-08-07T12:31:02.137-04:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn248","msg":"client metadata","attr":{"remote":"127.0.0.1:61402","client":"conn248","doc":{"driver":{"name":"mongo-csharp-driver","version":"2.11.0.0"},"os":{"type":"Windows","name":"Microsoft Windows 10.0.18362","architecture":"x86_64","version":"10.0.18362"},"platform":".NET Framework 4.8.4180.0"}}}
{"t":{"$date":"2020-08-07T12:31:02.235-04:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"connection accepted","attr":{"remote":"127.0.0.1:61404","sessionId":250,"connectionCount":3}}
{"t":{"$date":"2020-08-07T12:31:02.244-04:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn250","msg":"client metadata","attr":{"remote":"127.0.0.1:61404","client":"conn250","doc":{"driver":{"name":"mongo-csharp-driver","version":"2.11.0.0"},"os":{"type":"Windows","name":"Microsoft Windows 10.0.18362","architecture":"x86_64","version":"10.0.18362"},"platform":".NET Framework 4.8.4180.0"}}}
{"t":{"$date":"2020-08-07T12:31:02.297-04:00"},"s":"I",  "c":"ACCESS",   "id":20250,   "ctx":"conn250","msg":"Successful authentication","attr":{"mechanism":"SCRAM-SHA-256","principalName":"admin","authenticationDatabase":"admin","client":"127.0.0.1:61404"}}
{"t":{"$date":"2020-08-07T12:31:04.835-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn250","msg":"connection ended","attr":{"remote":"127.0.0.1:61404","connectionCount":1}}
{"t":{"$date":"2020-08-07T12:31:04.835-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn248","msg":"connection ended","attr":{"remote":"127.0.0.1:61402","connectionCount":2}}
{"t":{"$date":"2020-08-07T12:31:05.334-04:00"},"s":"W",  "c":"NETWORK",  "id":4615610, "ctx":"conn249","msg":"Failed to check socket connectivity","attr":{"error":"The operation completed successfully."}}
{"t":{"$date":"2020-08-07T12:31:05.334-04:00"},"s":"I",  "c":"-",        "id":20883,   "ctx":"conn249","msg":"Interrupted operation as its client disconnected","attr":{"opId":4183920}}
{"t":{"$date":"2020-08-07T12:31:05.334-04:00"},"s":"I",  "c":"NETWORK",  "id":22989,   "ctx":"conn249","msg":"Error sending response to client. Ending connection from remote","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"Connection reset by peer"},"remote":"127.0.0.1:61403","connectionId":249}}
{"t":{"$date":"2020-08-07T12:31:05.334-04:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn249","msg":"connection ended","attr":{"remote":"127.0.0.1:61403","connectionCount":0}}

推荐答案

问题是截至撰写本文时,MongoDB.Driver v2.11.0 已被窃听.它使用的库中存在某种不兼容性,如果您降级到 MongoDB.Driver v2.10.4,它可以完美运行.

The issue is as of the time of writing this the MongoDB.Driver v2.11.0 is bugged. There is some sort of incompatibility in the library it's using that if you downgrade to MongoDB.Driver v2.10.4 it works perfectly.

它不能完美"地工作;正如我所描述的.实际上,一个主要问题是我不能在 2.10.4 的任何查找操作中使用 allowDiskUse.它似乎不接受它或根本不起作用.

Edit : It doesn't work "perfectly" as i described. Actually one major problem is that i cannot use allowDiskUse on any find operation anymore with 2.10.4. It doesn't seem to accept it or work at all.

这篇关于仅在特定项目下的 MongoDB 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆