Skip to content

Commit 39ecea7

Browse files
committed
PR
1 parent 0620e0c commit 39ecea7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/MongoDB.Driver/Core/Clusters/Cluster.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,11 @@ public ServerSelectionWaitQueue(Cluster cluster)
456456

457457
public void Dispose()
458458
{
459-
_disposed = true;
460-
_rapidHeartbeatTimer.Dispose();
459+
lock (_serverSelectionWaitQueueLock)
460+
{
461+
_disposed = true;
462+
_rapidHeartbeatTimer.Dispose();
463+
}
461464
}
462465

463466
public IDisposable Enter(OperationContext operationContext, IServerSelector selector, ClusterDescription clusterDescription, long? operationId)

tests/MongoDB.TestHelpers/XunitExtensions/TimeoutEnforcing/UnobservedExceptionTestDiscoverer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System.Collections.Concurrent;
1617
using System.Collections.Generic;
1718
using System.Threading.Tasks;
1819
using Xunit;
@@ -27,6 +28,8 @@ public class UnobservedExceptionTrackingFactAttribute: FactAttribute
2728

2829
public class UnobservedExceptionTestDiscoverer : IXunitTestCaseDiscoverer
2930
{
31+
private static readonly ConcurrentBag<string> __unobservedExceptions = new();
32+
3033
private readonly IMessageSink _diagnosticsMessageSink;
3134

3235
public UnobservedExceptionTestDiscoverer(IMessageSink diagnosticsMessageSink)
@@ -35,7 +38,7 @@ public UnobservedExceptionTestDiscoverer(IMessageSink diagnosticsMessageSink)
3538
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionEventHandler;
3639
}
3740

38-
public static readonly List<string> UnobservedExceptions = new();
41+
public static IReadOnlyCollection<string> UnobservedExceptions => __unobservedExceptions;
3942

4043
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
4144
{
@@ -49,6 +52,6 @@ public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions disco
4952
}
5053

5154
void UnobservedTaskExceptionEventHandler(object sender, UnobservedTaskExceptionEventArgs unobservedException) =>
52-
UnobservedExceptions.Add(unobservedException.Exception.ToString());
55+
__unobservedExceptions.Add(unobservedException.Exception.ToString());
5356
}
5457

0 commit comments

Comments
 (0)