I am currently trying to run my pact.net example tests in a docker container , however I am getting the following error:
Starting test execution, please wait...
pact-consumer-tests | [xUnit.net 00:00:19.9436627]
pact_consumer.tests.AddConsumerTest.Add_customer [FAIL]
pact-consumer-tests | Failed
pact_consumer.tests.AddConsumerTest.Add_customer
pact-consumer-tests | Error Message:
pact-consumer-tests | System.AggregateException : One or more errors
occurred. (One or more errors occurred. (Cannot assign requested
address)) (The following constructor parameters did not have matching
fixture data: ConsumerApiPact data)
pact-consumer-tests | ---- System.AggregateException : One or more
errors occurred. (Cannot assign requested address)
pact-consumer-tests | -------- System.Net.Http.HttpRequestException :
Cannot assign requested address
pact-consumer-tests | ------------ System.Net.Sockets.SocketException
: Cannot assign requested address
pact-consumer-tests | ---- The following constructor parameters did
not have matching fixture data: ConsumerApiPact data
pact-consumer-tests | Stack Trace:
pact-consumer-tests |
pact-consumer-tests | ----- Inner Stack Trace #1
(System.AggregateException) -----
pact-consumer-tests | at
PactNet.Mocks.MockHttpService.Host.RubyHttpHost.Start() in
C:\projects\pact-
net\PactNet\Mocks\MockHttpService\Host\RubyHttpHost.cs:line 65
pact-consumer-tests | at PactNet.PactBuilder.MockService(Int32
port, JsonSerializerSettings jsonSerializerSettings, Boolean enableSsl,
IPAddress host) in C:\projects\pact-net\PactNet\PactBuilder.cs:line 82
pact-consumer-tests | at
pact_consumer.tests.context.ConsumerApiPact..ctor() in /app/pact-
consumer.tests/context/ConsumerApiPact.cs:line 27
pact-consumer-tests | ----- Inner Stack Trace -----
pact-consumer-tests | at
System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port,
CancellationToken cancellationToken)
....
Whatever I send into the framework for the Host IPAddress.Any AND IpAddress.Loopback but I still seem to get this issue?
Am I missing something? Its running in a docker container with no other service running..
I can run this on OSX using dotnet test and all is well.
Many thanks in advance
Richard
System.Net.Sockets.SocketException : Cannot assign requested address definitely looks like the system is unable to bind to a port - are you sure that port is available on the host (not just the Docker container)?
I have had the same error but in c#. The same technique could be used on the ruby problem. I into the issue with a dotnet application running in a docker container. The quick answer is that it's probably trying to connect to something and nothing is listening or it cant get to it, so you'll need to enable some networking hooks in the docker line. For the remainder part of this answer, I'll show how I came to that conclusion. I'm running EchoBot which I downloaded from Github:
https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/02.echo-bot
First we build that into a container and deploy it and try to use it from the bot emulator to reproduce the error. The emulator is running on my desktop and connects to the bot over port 3978.
Start a echobot container and use it from the emulator to see the original error:
$ docker run --rm -it --entrypoint=bash -p 3978:3978 myImage
# dotnet EchoBot1.dll
...
info: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
Sending activity. ReplyToId: adfa9af0-5f17-11ea-8765-033688f22eac
fail: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
[OnTurnError] unhandled error : Cannot assign requested address
System.Net.Http.HttpRequestException: Cannot assign requested address ---> System.Net.Sockets.SocketException: Cannot assign requested address
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
You can see that there is a socket exception with the cannot assign socket error. We can remove docker from the equation to see if the error changes.
Remove docker from the picture to see the error
$ dotnet run
...
info: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
Sending activity. ReplyToId: 3a427871-5f18-11ea-8765-033688f22eac
fail: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
[OnTurnError] unhandled error : Connection refused
System.Net.Http.HttpRequestException: Connection refused ---> System.Net.Sockets.SocketException: Connection refused
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
You can see that the error is really a Connection Refused when the same code runs outside of docker. So what can we do to see where its connecting to? if you're on linux you can run tcpdump or wireshark on windows.
Capture the network packets to see if there is an outbound connection
$tcpdump -ilo -n -v | tee tcpdump-output
...
19:38:45.336179 IP (tos 0x0, ttl 64, id 12504, offset 0, flags [DF], proto TCP (6), length 60)
127.0.0.1.46215 > 127.0.0.1.52148: Flags [S], cksum 0xfe30 (incorrect -> 0xea5f), seq 549373294, win 65495, options [mss 65495,sackOK,TS val 3769835141 ecr 0,nop,wscale 7], length 0
There is going to be a lot of junk in there, so I tee the output to a file and then use an editor to remove thee lines that are distracting (like DNS queries) but you can see that something is trying to connect over to port 52148.
It turns out that the local emulator is listening on the same port so I need to connect that port over to my desktop where the emulator is running. There are many ways to do this, but I prefer the older SSH way which is convenient.
Hook up a listening tunnel
$ ssh nmishr#104.xxx.xxx.xxx -R 52148:localhost:52148
Once I hooked up the listener on my local host machine to be listening we need to enable the docker container to talk to the host machine and the error goes away:
Run docker with --network=host
$ docker run --rm -it --entrypoint=bash --network=host myImage
# dotnet EchoBot1.dll
...
info: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
Sending activity. ReplyToId: c321ebb1-5f1a-11ea-8765-033688f22eac
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action method EchoBot1.Controllers.BotController.PostAsync (EchoBot1), returned result Microsoft.AspNetCore.Mvc.EmptyResult in 518.6485ms.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action EchoBot1.Controllers.BotController.PostAsync (EchoBot1) in 550.6136ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 687.9129ms 200
Related
The following error occurs when I start the dotdocker sudo dotdocker start for my project. There was no error before and it was working successfully. However, this error appeared without any changing on the project code. The version of docker-compose and dotdocker are 1.21.2 and 1.4.2 respectively. I tried several things to solve the problem but nothing is working such as::
1 - sudo dotstart stop
2 - sudo systemctl restart NetworkManager
3 - sudo service docker restart
❯ Start dotdocker containers
❯ Start proxy
↓ Pulling codekitchen/dinghy-http-proxy:latest [skipped]
→ Image already exists
↓ Creating dotdocker-proxy [skipped]
→ Container already created
✖ Starting dotdocker-proxy
→ (HTTP code 500) server error - driver failed programming external conn
…
✔ Start dnsmasq
Setting up DNS
(node:4314) UnhandledPromiseRejectionWarning: Error: (HTTP code 500) server error - driver failed programming external connectivity on endpoint dotdocker-proxy (4e8078f31f05224f8041e65026e179114701636bbd13eb71a67382ccae860db9): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use
at /usr/local/lib/node_modules/dotdocker/node_modules/docker-modem/lib/modem.js:257:17
at getCause (/usr/local/lib/node_modules/dotdocker/node_modules/docker-modem/lib/modem.js:287:7)
at Modem.buildPayload (/usr/local/lib/node_modules/dotdocker/node_modules/docker-modem/lib/modem.js:256:5)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/dotdocker/node_modules/docker-modem/lib/modem.js:232:14)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1244:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4314) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4314) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I haven't used the dotdocker but from what I see from the error and specifically this part:
tcp 0.0.0.0:80: bind: address already in use
Something in your system is already using port 80 that your program wants to use.
In order to see what is using port 80 you can try:
lsof -P -S 2 -i "tcp:80" | grep "\(:80->.*:\|:80 (LISTEN)$\)"
This will give you the info and the process id in the second column.
For example:
apache2 1914 root 4u IPv6 11920 0t0 TCP *:80 (LISTEN)
You can then kill this process that occupying the port you want to use by:
kill -KILL 1914
Edit - this is on OSX
Also, I've tried running minikube service <service-name>, that's shown below and when it tries to open it in a browser I get a "connection refused" signal because the port is closed.
I have a kubernetes deployment that works fine when using --driver=virtualbox. I translated this to use --driver=docker and this almost works except when I do the following
$ minikube service websocket-nodeport
|-----------|--------------------|-------------|-------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------------|-------------|-------------------------|
| default | websocket-nodeport | 9000 | http://172.17.0.4:30007 |
|-----------|--------------------|-------------|-------------------------|
🏃 Starting tunnel for service websocket-nodeport.
|-----------|--------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------------|-------------|------------------------|
| default | websocket-nodeport | | http://127.0.0.1:62032 |
|-----------|--------------------|-------------|------------------------|
🎉 Opening service default/websocket-nodeport in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
But if I go to
$ curl http://127.0.0.1:62032
curl: (7) Failed to connect to 127.0.0.1 port 62032: Connection refused
nothing happens, it isn't a valid address. However, if I do the following
$ minikube ssh
# inside the VM now
docker#minikube:~$ curl http://172.17.0.4:30007
ok!: websocket-frontend-b7c8dc4b9-5jtg6
I get the response I want! So this means that my service is running and the URL output of the websocket-nodeport address as is internal to minikube is correct but for some reason the local address http://127.0.0.1:62032 isn't be forwarded to the minikube VM.
How do I get this forward to work?
$ minikube service <service-name>
this will open up a tunnel to connect to the service, make sure the service is a NodePort service.
If it opens a browser and you get a 404 this is because the url in the address bar doesn't exist within your api. Changing the URL PATH to correct URL paths/routes you defined in your API should fix this
To open exposed service run following
$ minikube service <service-name>
This command will open the specified service in your default browser.
When I try composer-rest-server -c acme-admin#test-bna I get this output:
Discovering the Returning Transactions..
Discovered types from business network definition
Generating schemas for all types in business network definition ...
Generated schemas for all types in business network definition
Adding schemas for all types to Loopback ...
Added schemas for all types to Loopback
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Server.setupListenHandle [as _listen2] (net.js:1360:14)
at listenInCluster (net.js:1401:12)
at Server.listen (net.js:1485:7)
at module.exports.promise.then.then (/usr/local/lib/node_modules/composer-rest-server/cli.js:143:19)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
I am actually doing a udemy course about how to setup a hyperledger multi org network.
The error is showing that the port 3000 is busy.
EADDRINUSE means some process is already running on that port.
You can find the process by using the following command:
sudo ss -lptn 'sport = :3000'
It will return you process id, then you can kill it by:
sudo kill -9 process_id
The problem was that some process was running on the port 3000. This command fixed it.
fuser -n tcp -k 3000
My docker service (epst) fails to start if I'm also running VSCode. The error is:
ERROR: for epst Cannot start service epst: driver failed programming external connectivity on endpoint epst (long-hash): Error starting userland proxy: Bind for 0.0.0.0:5123 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
If I shut down VSCode and re-launch docker-compose, then everything comes up fine.
So my question is how do I identify what is binding to port 5123 in VSCode?
I believe you might be looking for lsof -i :5123?
See man page for lsof.
This would the return a list of processes running on the port you entered (5123).
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
appName 5123 yourUser -- ---- -------------------------
You could then kill 5123 to free up the desired port.
I was following this tutorial of building a simple chaincode in dev mode here.
I'm stuck here
First I cleared everything with docker rm -f $(docker ps -aq).
When I enter docker-compose -f docker-compose-simple.yaml up it ends with this Error: Error getting broadcast client: Error connecting to orderer:7050 due to context deadline exceeded
cli | Usage:
cli | peer channel create [flags]
cli |
orderer | 2017-12-05 20:44:53.681 UTC [orderer/common/deliver] Handle -> WARN 0d1 Error reading from stream: rpc error: code = Canceled desc = context canceled
orderer | 2017-12-05 20:44:53.681 UTC [orderer/main] func1 -> DEBU 0d2 Closing Deliver stream
cli exited with code 1
What is causing problem? Is it dns problem that it can't find orderer?
Alright, I finally figured that out, the problem is in network, so I had in my virtual machine parameters set NAT for network, and nothing worked. I've set it to bridge mode and everything worked fine.