Operation Cancelled on CheckConnection
See original GitHub issueHello, So I’m using a remote mongoDB Atlas service to host my mongo cluster, and the connection string is in this format:
mongodb+srv://user:pass@cluster-id.mongodb.net/database?retryWrites=true&w=majority.
I have tried using multiple variations of it within the UseMongoClient method, and it does goes fine up to the CheckConnection method, where it throws a ThrowOperationCancelledException, when reaching this piece of code on the MongoStorage class:
try { _dbContext.Database.RunCommand((Command<BsonDocument>)"{ping:1}", cancellationToken: cts.Token); } catch (Exception e) { throw new MongoConnectException(_dbContext, CreateObscuredConnectionString(), e); }
The exception message is not very descriptive, just says:
The operation was canceled.
Here is the exception stack trace:
at System.Threading.CancellationToken.ThrowOperationCanceledException() at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask) at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken) at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken) at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken) at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken) at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken) at MongoDB.Driver.MongoDatabaseImpl.UsingImplicitSession[TResult](Func
2 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoDatabaseImpl.RunCommand[TResult](Command1 command, ReadPreference readPreference, CancellationToken cancellationToken) at Hangfire.Mongo.MongoStorage.CheckConnection() in D:\Users\Felipe\Documents\Source\Repos\Hangfire.Mongo\src\Hangfire.Mongo\MongoStorage.cs:line 79
It’d be awesome if somebody could help shed a light on this. Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Ok, it’s just the cancellationToken that is too short, as it’s set to 1 second. MongoAtlas in some situations can reply to a ping after 1 second, hence the command gets cancelled, throwing the exception
MongoConnectException(_dbContext, CreateObscuredConnectionString(), e);
On MongoStorage.cs:75 maybe the timeout for the cancellationToken should be configurable?
closing