Skip to content

Investigation of empty ServiceIP on HydraRouter dashboard #13

@cjus

Description

@cjus

The check for ServiceIP == null or string.Empty fails on AWS Fargate (and perhaps other environments).
The if statement returns false and so ServiceIP isn't being set to a value.

https://github.com/pnxtech/Hydra4Net-Development/blob/master/Hydra4NET/Hydra.cs#L144

              if (ServiceIP == null || ServiceIP == string.Empty)
              {
                  using Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0);
                  socket.Connect("8.8.8.8", 65530);
                  if (socket.LocalEndPoint is IPEndPoint endPoint)
                  {
                      ServiceIP = endPoint.Address.ToString();
                  }
              }

I think we should replace the contents of the if (ServiceIP == null || ServiceIP == string.Empty) statement with:

   var name = Dns.GetHostName();
   ServiceIP = Dns.GetHostEntry(name).AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions