Sails rejecting PostgreSQL connection with sails-postgresql module - node.js

I have a sails web app in an intranet environment. An average of ~12 users are logged in at the same time. Eventually I get the classic connection refused message from sails-postgresql that lasts for at least 3 minutes, denying all http requests made to the app.
Error creating a connection to Postgresql using the following settings:
{
...
schema: true,
ssl: false,
adapter: 'sails-postgresql',
poolSize: 50
...
}
I either get { [Error: write ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'write' } or { [Error: write ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }.
My PostgreSQL logs the following message:
No connection could be made because the target machine actively refused it.
As you can see, my poolSize in sails.config.connections is set to 50 and my max_connections in postgresql.conf is set to 100. I'm not using this database for something else.
Is my poolsize set ok? Is it a problem from Sails or is it Postgres'?

Try increasing max_connections in postgres config file postgresql.conf, in my Ubuntu 15.04 linux it is located in this path:
/etc/postgresql/9.4/main/postgresql.conf

Related

heroku postgres ETIMEDOUT when conencting through localhost

I have a website which uses the free tier of heroku postgres I was running it on localhost and it was working just fine till today no changes were made to the code and the database url and everything is just fine
Error: connect ETIMEDOUT 3.224.164.189:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1246:16) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '3.224.164.189',
port: 5432
}
This is the error which I get and this error is only shown on localhost, when the same code is deployed to heroku, it works just fine
Also, one thing which I've noticed is that it works just fine when I use my mobile network and this issue only occurs when I use my ethernet connection.
Can Someone help me out with this sticky situation?

NetworkingError: getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com:443

There is a table say company. If we try to get the company by it primary key we get the following error.
PLEASE NOTE: This error is not for all instances. It is not repeatedly getting failed. It occurs sometimes but often. 20% of requests are failing
{ Error: getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com:443
at Object._errnoException (util.js:1022:11)
at errnoException (dns.js:55:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
message: 'getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com:443',
code: 'NetworkingError',
errno: 'EMFILE',
syscall: 'getaddrinfo',
hostname: 'dynamodb.eu-west-1.amazonaws.com',
host: 'dynamodb.eu-west-1.amazonaws.com',
port: 443,
region: 'eu-west-1',
retryable: true,
time: 2019-07-18T05:30:09.145Z }
There was a discussion on aws/aws-sdk-js-v3 with issue #3019 where it was recommended to lower the socket timeouts.
This happened to me too when I used the agent as below
new https.Agent({
keepAlive: true,
maxSockets: Infinity,
}
Then I looked more into the documentation here at Reusing Connections with Keep-Alive in Node.js and what I found was an interesting thing
The easiest way to configure SDK for JavaScript to reuse TCP connections is to set the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable to 1. This feature was added in the 2.463.0 release.
So, I removed the httpsAgent from the AWS DynamoDBClient connection and added the required environment variable -
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
The error was resolved and things were working as expected.
I hope somebody might find this answer helpful.

Watson conversation in nodejs giving ETIMEDOUT error

Hello everyone I'm trying to test an example similar to Watson Conversation Example, but with my workspace id and my own credentials of course, but I'm getting in every call the following error:
{ code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect',
address: '158.85.132.88', port: 443 }
Could anyone have any idea of what is going on here, please?

zoho email imap connection using node-imap is getting timeout in aws instance

I am using node-imap to connect and read zoho mail from my nodejs application, I am getting timeout err as below in AWS ubuntu instance, But in my local it is getting connected fine.
{ [Error: connect ETIMEDOUT]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
source: 'socket' }
Do i need to open any socket in AWS to use imap?
If so how i can do that?
You help regarding this is highly appreciated.
Thanks.

Node function on AWS Lambda can't connect to database with node-pg

My function works locally, but, when I deploy to AWS Lambda, it can't seem to connect to my postgres database. Here's the error:
{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }, isOperational: true, code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }
My database is hosted on an Azure virtual machine, and I'm not having problems connecting to it from any other app nor from this app when run locally. What could be causing the connection to fail when running on Lambda?
It turned out to be something dumb. I am using node-lambda and thought the .env file it creates was propagated to the function's environment. Logging my DB connection string showed this wasn't the case. Once I set that, everything was golden.

Resources