[CSHARP-3436] NullReferenceException in ServerMonitor Created: 25/Feb/21  Updated: 25/Feb/21  Resolved: 25/Feb/21

Status: Closed
Project: C# Driver
Component/s: Internal
Affects Version/s: 2.11.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Aristarkh Zagorodnikov Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: SDAM
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-3188 Research timeout exception handling o... Closed

 Description   

It appears that there is a state management issue in ServerMonitor.
When the target replicaset is failing over, one of the threads fails with NullReferenceException, see exception callstack below:

System.NullReferenceException: Object reference not set to an instance of an object.
void MongoDB.Driver.Core.Servers.ServerMonitor.CancelCurrentCheck()
void MongoDB.Driver.Core.Servers.Server.HandleBeforeHandshakeCompletesException(IConnection connection, Exception ex)
IChannelHandle MongoDB.Driver.Core.Servers.Server.GetChannel(CancellationToken cancellationToken)
IChannelHandle MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken cancellationToken)
IChannelHandle MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken cancellationToken)
RetryableReadContext MongoDB.Driver.Core.Operations.RetryableReadContext.Create(IReadBinding binding, bool retryRequested, CancellationToken cancellationToken)
IAsyncCursor<TDocument> MongoDB.Driver.Core.Operations.FindOperation<TDocument>.Execute(IReadBinding binding, CancellationToken cancellationToken)
TResult MongoDB.Driver.OperationExecutor.ExecuteReadOperation<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken)
TResult MongoDB.Driver.MongoCollectionImpl<TDocument>.ExecuteReadOperation<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, ReadPreference readPreference, CancellationToken cancellationToken)
TResult MongoDB.Driver.MongoCollectionImpl<TDocument>.ExecuteReadOperation<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, CancellationToken cancellationToken)
IAsyncCursor<TProjection> MongoDB.Driver.MongoCollectionImpl<TDocument>.FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken)
IAsyncCursor<TProjection> MongoDB.Driver.MongoCollectionImpl<TDocument>.FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken)+(IClientSessionHandle session) => { }
TResult MongoDB.Driver.MongoCollectionImpl<TDocument>.UsingImplicitSession<TResult>(Func<IClientSessionHandle, TResult> func, CancellationToken cancellationToken)
IAsyncCursor<TProjection> MongoDB.Driver.MongoCollectionImpl<TDocument>.FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options, CancellationToken cancellationToken)

While I don't have debug symbols with line numbers (and optimized/JITted code would not indicate the target line with 100% certainty), I believe the Dispose call is the culprit here.



 Comments   
Comment by Dmitry Lukyanov (Inactive) [ 25/Feb/21 ]

this has been fixed in CSHARP-3188

Comment by Aristarkh Zagorodnikov [ 25/Feb/21 ]

Please see https://github.com/mongodb/mongo-csharp-driver/pull/465 for a proposed (trivial) fix.

Generated at Wed Feb 07 21:45:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.