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
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
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
I want to use composer-rest-server to generate rest api.
1,I run composer network ping -c admin#trade-network
the result is :
```The connection to the network was successfully tested: trade-network
Business network version: 0.2.6-20180530153450
Composer runtime version: 0.19.8
participant: org.hyperledger.composer.system.NetworkAdmin#admin
identity: org.hyperledger.composer.system.Identity#8633aef10e9d998be8bec4bb4ab535eb74e3d6832cb21286b89cadf0e95863c5
Command succeeded
2,run `docker run -e COMPOSER_CARD=admin#trade-network -e COMPOSER_NAMESPACES=never --name rest -p 3000:3000 hyperledger/composer-rest-server`
while error appears:
[2018-06-15 08:18:17] PM2 log: Launching in no daemon mode
[2018-06-15 08:18:17] PM2 log: Starting execution sequence in -fork mode- for app name:composer-rest-server id:0
[2018-06-15 08:18:17] PM2 log: App name:composer-rest-server id:0 online
WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
Discovering types from business network definition ...
Exception: Error: Error trying to ping. Error: REQUEST_TIMEOUT
Connection fails: Error: Error trying to ping. Error: REQUEST_TIMEOUT
It will be retried for the next request.
Error: Error trying to ping. Error: REQUEST_TIMEOUT
at _checkRuntimeVersions.then.catch (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:790:34)
at
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
[2018-06-15 08:23:21] PM2 log: App [composer-rest-server] with id [0] and pid [15], exited with code [1] via signal [SIGINT]
[2018-06-15 08:23:21] PM2 log: Starting execution sequence in -fork mode- for app name:composer-rest-server id:0
[2018-06-15 08:23:21] PM2 log: App name:composer-rest-server id:0 online
WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
Discovering types from business network definition ...
Connection fails: Error: Error trying to ping. Error: REQUEST_TIMEOUT
It will be retried for the next request.
Exception: Error: Error trying to ping. Error: REQUEST_TIMEOUT
Error: Error trying to ping. Error: REQUEST_TIMEOUT
```
so I want to ask why?
This is a networking issue ... The URL values in your connection.json (part of the "Card") have localhost in them which works fine from the command line of your computer where Docker sets up Port forwarding into the containers of the Fabric. When you use the same card inside a rest container localhost loops back into the container and does not "see" the Fabric.
Step 6 of this tutorial deals with the problem by creating a special restadmin card, and modifying the addresses in the connection.json to 'find' the Fabric - Google Oauth2 Tutorial.
I assume you are already sharing a volume on the docker run command so that the Rest Container can find the folder with the cards. E.g. -v ~/.composer:/home/composer/.composer
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.
We need to run "composer" command outside of docker container's network.
When I specify orderer and peer host name (e.g. peer0.org1.example.com) in /etc/hosts file, "composer" command seems to work.
However, if I specify server's IP address, it does not work. Here is sample.
$ composer network list -p hlfv1 -n info-share-bc -i PeerAdmin -s secret
✖ List business network info-share-bc
Error trying to ping. Error: Error trying to query chaincode. Error: Connect Failed
Command succeeded
This is a command example when I specify host name in /etc/hosts.
$ composer network list -p hlfv1 -n info-share-bc -i PeerAdmin -s secret
✔ List business network info-share-bc
name: info-share-bc
models:
- org.hyperledger.composer.system
- bc.share.info
<snip>
I believe when the server name can not be resolved, we will specify the option called "ssl-target-name-override", hyperledger node.js SDK as described here.
https://jimthematrix.github.io/Remote.html
- ssl-target-name-override {string} Used in test environment only,
when the server certificate's hostname (in the 'CN' field) does not
match the actual host endpoint that the server process runs at,
the application can work around the client TLS verify failure by
setting this property to the value of the server certificate's hostname
Is there any option to specify host name in connection profile (connection.json) ?
Found a work around: hostnameOverride option in connection profile resolved the connection issue.
"eventURL": "grpcs://<target-host>:17053",
"hostnameOverride": "peer0.org1.example.com",