Skip to content

Commit 5d7ffae

Browse files
committed
CSHARP-869: stop caching ip addresses.
1 parent 2c5cc36 commit 5d7ffae

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

MongoDB.Driver/Communication/MongoServerInstance.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public sealed class MongoServerInstance
5454
private Exception _connectException;
5555
private bool _inStateVerification;
5656
private ServerInformation _serverInfo;
57-
private IPEndPoint _ipEndPoint;
5857
private bool _permanentlyDisconnected;
5958
private int _sequentialId;
6059
private MongoServerState _state;
@@ -340,7 +339,7 @@ public MongoServerState State
340339
internal bool IsCompatible
341340
{
342341
get
343-
{
342+
{
344343
Range<int> serverRange;
345344
lock (_serverInstanceLock)
346345
{
@@ -358,16 +357,8 @@ internal bool IsCompatible
358357
/// <returns>The IP end point of this server instance.</returns>
359358
public IPEndPoint GetIPEndPoint()
360359
{
361-
// use a lock free algorithm because DNS lookups are rare and concurrent lookups are tolerable
362-
// the intermediate variable is important to avoid race conditions
363-
var ipEndPoint = Interlocked.CompareExchange(ref _ipEndPoint, null, null);
364-
if (ipEndPoint == null)
365-
{
366-
var addressFamily = _settings.IPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
367-
ipEndPoint = _address.ToIPEndPoint(addressFamily);
368-
Interlocked.CompareExchange(ref _ipEndPoint, _ipEndPoint, null);
369-
}
370-
return ipEndPoint;
360+
var addressFamily = _settings.IPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
361+
return _address.ToIPEndPoint(addressFamily);
371362
}
372363

373364
/// <summary>
@@ -540,7 +531,7 @@ internal void Disconnect()
540531
}
541532

542533
// we know for certain state has just changed.
543-
OnStateChanged();
534+
OnStateChanged();
544535

545536
try
546537
{

0 commit comments

Comments
 (0)