Skip to content

Use user defined loopback address if available (#374) #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions RabbitMQ.Stream.Client/StreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public async Task<StreamInfo> StreamInfo(string streamName)
// when theres 1 endpoint and an address resolver, there could be a cluster behind a load balancer
var forceLocalHost = false;
var localPort = 0;
var localHostOrAddress = "";
if (_clientParameters.Endpoints.Count == 1 &&
_clientParameters.AddressResolver is null)
{
Expand All @@ -342,10 +343,12 @@ public async Task<StreamInfo> StreamInfo(string streamName)
case DnsEndPoint { Host: "localhost" } dnsEndPoint:
forceLocalHost = true;
localPort = dnsEndPoint.Port;
localHostOrAddress = dnsEndPoint.Host;
break;
case IPEndPoint ipEndPoint when Equals(ipEndPoint.Address, IPAddress.Loopback):
case IPEndPoint ipEndPoint when IPAddress.IsLoopback(ipEndPoint.Address):
forceLocalHost = true;
localPort = ipEndPoint.Port;
localHostOrAddress = ipEndPoint.Address.ToString();
break;
}
}
Expand All @@ -354,7 +357,7 @@ public async Task<StreamInfo> StreamInfo(string streamName)
if (forceLocalHost)
{
// craft the metadata response to force using localhost
var leader = new Broker("localhost", (uint)localPort);
var leader = new Broker(localHostOrAddress, (uint)localPort);
metaStreamInfo = new StreamInfo(streamName, ResponseCode.Ok, leader,
new List<Broker>(1) { leader });
}
Expand Down