Issues while testing a node.js server with siege - node.js

I was doing some load testing for my node.js server(a small webapp) using siege. I could see that for even small number of concurrent connection like 300, it showed some errors
siege -c 300 -n myserver.com:3000
Then I could see some results like
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
[error] socket: read error Connection reset by peer sock.c:460: Connection reset by peer
I could see that the server is closing the connections. Why is it so. How can I debug it. I have a server running on Macbook pro with 4GB memory. I want to let you know that I have used websockets. That is the clients visit a page returned by the web server running on node.js . This page then uses websockets to connect to the same server for two way communication. What could cause such issue?

When running into a situation where you belive you may be running out of sockets, there are two things to confirm.
Check that you are closing your sockets explicitly. In some languages the garbage collector's finalization logic will clean up after you, but this involves lag and is sloppy; in other languages that don't do this, your application will "leak" sockets (and thus file handles) until it terminates.
Make your OS allows your application's user account enough peak sockets for your test.
To address point 1: Are you closing your sockets? I am not a heavy node.js user, but I think:
var conn = new net.Socket();
conn.destroy(); //Are you doing this?
To address point 2: Set the hard and soft open file limit to something high enough to stay out of your way:
launchctl limit maxfiles 8192 8192
Running sudo launchctl limit with no arguments should print out your current limits. Check out the Apple documentation for launchctl for more details.

Related

rafthttp: dial tcp timeout on etcd 3-node cluster creation

I don't have an access to the etcd part of the project's source code, however I do have access to the /var/log/syslog.
The goal is to setup up 3-node cluster.
(1)The very first etcd error that comes up is:
rafthttp: failed to dial 76e7ffhh20007a98 on stream MsgApp v2 (dial tcp 10.0.0.134:2380: i/o timeout)
Before continuing, I would say that I can ping all three nodes from each of the nodes. As well as I have tried to open the 2380 TCP ports and still no success - same error.
(2)So, before that error I had following messages from the etcd, which in my opinion confirm that cluster is setup correctly:
etcdserver/membership: added member 76e7ffhh20007a98 [https://server2:2380]
etcdserver/membership: added member 222e88db3803e816 [https://server1:2380]
etcdserver/membership: added member 999115e00e17123d [https://server3:2380]
In /etc/hosts file these DNS names are resolved as:
server2 10.0.0.135
server1 10.0.0.134
server3 10.0.0.136
(3)The initial setup, however (on each nodes looks like this):
embed: listening for peers on https://127.0.0.1:2380
embed: listening for client requests on 127.0.0.1:2379
So, to sum up, each node have got this initial setup log (3) and then adds members (2) then once these steps are done it fails with (1). As I know the etcd cluster creation is following this pattern: https://etcd.io/docs/v3.5/tutorials/how-to-setup-cluster/
Without knowing the source code is really hard to debug, however maybe some ideas on the error and what could cause it?
UPD: etcdctl cluster-health output (ETCDCTL_ENDPOINT is exported):
cluster may be unhealthy: failed to list members Error: client: etcd
cluster is unavailable or misconfigured; error #0: client: endpoint
http://127.0.0.1:2379 exceeded header timeout ; error #1: dial tcp
127.0.0.1:4001: connect: connection refused
error #0: client: endpoint http://127.0.0.1:2379 exceeded header
timeout error #1: dial tcp 127.0.0.1:4001: connect: connection refused

Hyperledger Fabric, javascript fabcar chaincode error. Transport: error while dialing: dial tcp 127.0.0.1:7051: connect: connection refused

I am having the same problem with Hyperledger fabric 2.1.1, but I am able to run test network with default options, but when I try to run Fabcar javascript chaincode I get an error:
Error: error getting endorser client for channel: endorser client failed to connect to localhost:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:7051: connect: connection refused"
I have tried everything mentioned in thread Error deploying Fabric test-network fabcar chaincode, removed docker images, ran prune, removed organizations data and fired ./network.sh up createChannel -ca -c mychannel -s couchdb -i 2.1.1, but the error is still there. Also, my RAM is 16Gb, so the problem is not there. Any other suggestion, please ?
This situation is happened because you called a gRPC to 127.0.0.1:7051 server but your call failed to hit the server. This situation may happen for many reasons, but for most of the cases the situation is happened due to server down(server exit or down due to misconfiguration) or for wrong certificate or your call failed to hit the server due to misconfiguration.
Please check the following docker container and ensure that is running properly.

Fabic: Issue connection refused 7050

I am trying to create a network from the hyperledger fabic tutorial. I get the following error:
Error: failed to create deliver client for orderer: orderer client failed to connect to localhost:7050: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp [::1]:7050: connect: connection refused"
I opened up the port on the Centos 7 Virtual machine and still no luck. The docker container is exposing the port to the host.
I removed all docker containers, images and volumes. I even rebuilt the VM from scratch.
Any help would be great.
Thanks,
This situation is happened because you called a gRPC to orderer server but your call failed to hit the server. This situation may happen for many reasons, but for most of the cases the situation is happened due to server down(orderer server exit or down due to misconfiguration) or your call failed to hit the server due to misconfiguration.
I somehow encounter this problem before and the port was opened. Somehow it was a mistake where I forgot to put '-a' in command (launch cerificate authorities). Hope it help.
You might also refer this : https://hyperledger-fabric.readthedocs.io/en/release-2.0/build_network.html

Linux fetchmail POP3 connection error

Slackware OS, trying to setup fetchmail
I have coded this .fetchmailrc file:
set daemon 600 //fetches mail every hour or 60 minutes.
set logfile /root/fetchmail.log
poll 10.200.***.** protocol POP3
user "bob" password "bob" is "bob" here preconnect "date>>/root/fetchmail.log"
ssl
no rewrite
keep
It worked before but now it is failing to retrieve mail, i checked the fetchmail.log file and i get this error:
Thu Nov 5 10:15:32 GMT 2015
fetchmail: connection errors for this poll:
name 0: connection to 10.200.***.**:pop3s [10.200.***.**/995] failed: Connection refused.
fetchmail: POP3 connection to 10.200.***.** failed: Connection refused
fetchmail: Query status=2 (SOCKET)
I've reset the daemons, ended the process and no progress.
I had exactly the same problem on a Mageia 5 Linux. Apparently, I
solved it by redoing network configuration, which the Mageia can do
with a single click on the relevant Configure button in the Network
Center window.
I did not touch my .fetchmailrc file.

ECONNREFUSED error when connecting to mongodb from node.js

I know I'm doing some very stupid and noobish, but I'm hoping someone can help me set up a basic database connection to mongodb from node.js on a mac.
I've installed mongodb using homebrew, seems to have worked quite well. I have started the server (mongod) as the locally logged in user, and opened a second terminal and confirmed that I can connect to it by using mongo. When I run mongo I get the message "connecting to: localhost:27017/test" followed by a command prompt. Ran a few commands in the mongo shell everything seems to be working there. Left both terminals open and running.
I've also confirmed that I can reach the web interface at localhost:28017.
I installed node.js and added the mongoose package. Now attempting to connect using a super simple node.js app (also running as locally logged in user):
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
I receive the following error
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
Banging my head against the wall trying to get something so simple to work. What am I missing?
Edit: Here are the logs from mongod. As you can see I tried multiple times and they're all failing rather instantaneously:
Thu Dec 5 08:19:43.700 [initandlisten] MongoDB starting : pid=14412 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=mobadmins-MacBook-Pro-3.local
08:19:43.700 [initandlisten] db version v2.4.8
08:19:43.700 [initandlisten] git version: nogitversion
08:19:43.700 [initandlisten] build info: Darwin mobadmins-MacBook-Pro-3.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
08:19:43.700 [initandlisten] allocator: tcmalloc
08:19:43.700 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log", rest: true }
08:19:43.700 [initandlisten] journal dir=/usr/local/var/mongodb/journal
08:19:43.700 [initandlisten] recover : no journal files present, no recovery needed
08:19:43.729 [websvr] admin web console waiting for connections on port 28017
08:19:43.729 [initandlisten] waiting for connections on port 27017
08:22:34.561 [initandlisten] connection accepted from 127.0.0.1:52160 #3 (1 connection now open)
08:22:34.563 [conn3] recv(): message len 1124073472 is too large. Max is 48000000
08:22:34.563 [conn3] end connection 127.0.0.1:52160 (0 connections now open)
08:24:41.298 [initandlisten] connection accepted from 127.0.0.1:52166 #4 (1 connection now open)
08:24:41.304 [conn4] end connection 127.0.0.1:52166 (0 connections now open)
08:25:06.938 [initandlisten] connection accepted from 127.0.0.1:52168 #5 (1 connection now open)
08:25:06.943 [conn5] end connection 127.0.0.1:52168 (0 connections now open)
08:25:18.220 [initandlisten] connection accepted from 127.0.0.1:52172 #6 (1 connection now open)
08:25:18.225 [conn6] end connection 127.0.0.1:52172 (0 connections now open)
08:25:38.811 [initandlisten] connection accepted from 127.0.0.1:52175 #7 (1 connection now open)
08:25:38.816 [conn7] end connection 127.0.0.1:52175 (0 connections now open)
ECONNREFUSED error
There are few reasons of this error in node :
Your port is already serving some service so it will refuse your connection.
go to command line and get pid by using following command
$ lsof -i:port_number
Now kill pid by using
$ kill -9 pid(which you will get by above command)
Your server is not running e.g. in this case please check your mongoose server is running or run by using following command.
$ mongod
There is also possibility your localhost is not configured properly so use 127.0.0.1:27017 instead of localhost.
OK, this was another case of not being truly forthcoming in the info I posted above. My node.js app was very simple, but I was including another couple lines in my node.js code that apparently caused this issue.
Specifically, I had another variable declared which was calling some other code that made a separate database call using incorrect db info. This is why, when using Xinzz's code, the console log error seemed not to change. It wasn't actually the mongoose.connect command that was throwing the error!
Lesson learned, localize the problem and comment out unrelated code! Sorry guys, I knew this was me being dumb.
For me I had to change 'localhost' to '127.0.0.1' and then it started working again:
mongoose.connect('mongodb://127.0.0.1/test')
Use this code to setup your mongodb connection:
var mongoose = require('mongoose');
var mongoURI = "mongodb://localhost:27017/test";
var MongoDB = mongoose.connect(mongoURI).connection;
MongoDB.on('error', function(err) { console.log(err.message); });
MongoDB.once('open', function() {
console.log("mongodb connection open");
});
Make sure mongod is running while you start the server. Are you using Express or just a simple node.js server? What is the error message you get with the above code?
very strange, but in my case, i switch wifi connection...
I use some public wifi and switch to my phone connection
I had facing the same issue while writing a simple rest api using node.js
eventually found out it was due to wifi blockage and security reason .
try once connecting it using your mobile hotspot .
if this be the reason it will get resolved immediately.
I had same problem. It was resolved by running same code in Administrator Console.
I had the same issue. What I did is to run mongodb command in another terminal. Then, run my application in another tab. This resolved my problem. Though, I am trying other solution such as creating a script to run mongodb before connection is made.
sometimes you need to check the rightfulness of the IP, firewall, port forwarding, etc, if your target database is in other machines.
I had the same issue, all I did was add a setTimeout of about 10 seconds before trying to connect to the Mongo server and it solved the issue right up. I dont know why I had to add a delay but it worked...
I also got stucked with same problem so I fixed it like this :
If you are running mongo and nodejs in docker container or in docker compose
so replace localhost with mongo (which is container name in docker in my case) something like this below in your nodejs mongo connection file.
var mongoURI = "mongodb://mongo:27017/<nodejs_container_name>";
I manually started the mongodb service.
Control Panel -> Administrative tools -> Services -> Mongodb
Then either start/restart it. It's done!
Happy Coding! :-)
mongod was running fine locally on my system. I could connect to it with Mongo Compass, but mongoose simply refused to connect. The magic word is directConnection=true, as in
mongodb://127.0.0.1:27017/test?directConnection=true
Versions:
mongoose 6.5.2
mongodb 4.4.13 Community
node 18.5.0
If you're trying to connect to a remote MongoDB server and getting the ECONNREFUSED error, make sure the bind ip option is set up to 0.0.0.0.
See https://www.mongodb.com/docs/manual/core/security-mongodb-configuration/ for more information or use the MongoDB config file (mongod.conf, read more) like this:
net:
bindIp: 0.0.0.0
You can just use your local IP address (e.g. 127.0.0.1), instead of using localhost.
(localhost = 127.0.0.1:27017)
'mongodb://127.0.0.1:27017/<ele.Name>'
This is how i got my solution
Check this post. https://stackoverflow.com/a/57589615
It probably means that mongodb is not running. You will have to enable it through the command line or on windows run services.msc and enable mongodb.
I tried every possible solution,butit didn't help me. I took a break and I changed the following. Simple typo. May help someone is same situation.
From:
app.listen((port)=>console.log(Server is running at port ${PORT}))
To:
app.listen(PORT, console.log(Server is running at port ${PORT}))
The earlier got me to connect to database mongo atlas but get request was Error: connect ECONNREFUSED
you can go to mongoDB compass client and follow these steps:
1.Click Fill in connection fields individually:
2.In hostname type : 127.0.0.1
3. Click CONNECT.
Mongodb was not running but I had the module for node.js The database path was missing. Fix was create new folder in the root so run
sudo mkdir -p /data/db/
then run
sudo chown id -u /data/db
For my case this resolved:
Control Panel -> Administrative tools -> Services -> Start MongoDB Server
Hello this is fun and I mean it's fun. Headover to start button and typeservice from there ho Down to and look for mongodb.right click it and click start. Mongod will start. Go back to your project and thank me later

Resources