Skip to content
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

Should my URL be replaced with 'localhost' #1099

Closed
domwvitality opened this issue May 7, 2024 · 8 comments
Closed

Should my URL be replaced with 'localhost' #1099

domwvitality opened this issue May 7, 2024 · 8 comments
Assignees
Labels

Comments

@domwvitality
Copy link

When I try and configure a my WireMockServer to start with a specific address it is overwritten when created and replaced with 'localhost'.

Service = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "http://172.18.0.1:8102" }
});

The code above would create a new server with a URL of 'http://localhost:8102' instead of 'http://172.18.0.1:8102'

image

I noticed that version 1.1.10 is the last version which would set the URL to what I provided, anything after this replaced it with 'localhost'.

Is this expected behaviour?

@StefH StefH self-assigned this May 7, 2024
@StefH
Copy link
Collaborator

StefH commented May 7, 2024

172.18.0.1 is your private local ip-address?

@domwvitality
Copy link
Author

Yeah, that's correct.
Docker is used to start various services we depend on and they get assigned this address and an available port number

@StefH
Copy link
Collaborator

StefH commented May 7, 2024

I understand. The logic has been changed indeed. I'll change the code in #1100

And if you want, you can test a preview version 1.5.52-ci-18499, see
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH
Copy link
Collaborator

StefH commented May 13, 2024

@domwvitality
Did you have time to test the preview version?

@domwvitality
Copy link
Author

@StefH
Sure, will try and get that tested and confirmed today.

@domwvitality
Copy link
Author

Hi @StefH ,

Apologies for the delay. I've just got round to testing that build and it fails for me when starting the server. I'm using the same snippet...

Service = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "http://172.18.0.1:8102" }
});

but when I execute I get this error...

WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (Cannot assign requested address)
 ---> System.AggregateException: One or more errors occurred. (Cannot assign requested address)
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at WireMock.Server.WireMockServer..ctor(WireMockServerSettings settings)
   at WireMock.Server.WireMockServer.Start(WireMockServerSettings settings)

@StefH
Copy link
Collaborator

StefH commented May 17, 2024

On my system:

ipconfig

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::44c8:b60d:87e1:8437%27
   IPv4 Address. . . . . . . . . . . : 172.19.80.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

WireMock.Net

var serverOnPrivateIPAddress172_19 = WireMockServer.Start(new WireMockServerSettings
{
    Urls = new[] { "https://172.19.80.1:8103" }
});
System.Console.WriteLine($"{string.Join(", ", serverOnPrivateIPAddress172_19.Urls)}");
serverOnPrivateIPAddress172_19.Stop();

This works fine.

Are you sure you that 172.18.0.1 is your local ip-address from your PC?

@domwvitality
Copy link
Author

Hi @StefH ,

My apologies, you're right, the IP was wrong.
Retested with http://172.19.0.1 and all is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants