pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
73 stars 69 forks source link

TCPServer Error: Cannot assign requested address - bind(2) for "::1" port #79

Open waelemara opened 6 years ago

waelemara commented 6 years ago

Hi,

I have followed the instructions mentioned here https://github.com/pact-foundation/pact-ruby-standalone/releases for the Linux x64 platform.

When I run the this command ./pact-mock-service start I get the following message

INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] WARN TCPServer Error: Cannot assign requested address - bind(2) for "::1" port 9222 INFO WEBrick::HTTPServer#start: pid=671 port=9222

I see this warning "TCPServer Error" only on the Linux Platform, I have tried Windows and OSX and both are working fine. In the message it says it is a warning but in reality the server is not up or not accessible.

Steps to reproduce

docker run -it -p 9222:9222 microsoft/aspnetcore-build /bin/bash curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.18.0/pact-1.18.0-linux-x86_64.tar.gz tar xzf pact-1.18.0-linux-x86_64.tar.gz cd pact/bin ./pact-mock-service start

Can you please shed some light on this issue.

Thanks

dursk commented 6 years ago

What's your /etc/hosts look like? I was able to resolve by commenting out

::1 localhost ip6-localhost ip6-loopback

but it's less than desirable...

bethesque commented 6 years ago

Try setting an explicit --host=0.0.0.0 and --port=1234

waelemara commented 6 years ago

@dursk I have tried your option, it works, but the mock service is not accessible from outside the container. @bethesque I have tried your option and it is working as expected, and the mock service is accessible from outside the container.

netstat results after applying both options Option 1 tcp 0 localhost:1234 0.0.0.0: LISTEN Option 2 tcp 0 0 0.0.0.0:1234 0.0.0.0: LISTEN

ATM the second option is not viable for me as I'm using a wrapper library is there is a way to achieve the same netstat results but without passing --host flag?

I'm already working with the consumer library to have that option open in the API.

Thanks very much and appreciate your time.

bethesque commented 6 years ago

Neil should be able to get the fix out pretty quickly. The only other option is to do a small hack to the ruby file. Somewhere inside the .net code will be the ruby-standalone package. You'll have to do some exploring because I don't know where that is. Open up pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-{LATEST_VERSION}/lib/pact/mock_service/cli.rb

Find the line with desc 'start' (about line 52) then find the line method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost' Change the 'localhost' to '0.0.0.0'.

I believe the .net impl might actually be using the service command, so change the default in that one too (about line 20).