Not able to connect my service with Redis - node.js

My server is located on client premise.
I'm facing an issue, in that my service(node js) is not able to connect with redis.
If I'm checking the status of redis it's running fine.
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-02-15 14:16:34 EAT; 18h ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 3085148 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 19104)
Memory: 8.2M
CGroup: /system.slice/redis-server.service
I'm able to connect with the service manually from one server providing host and port.
But the issue is when my service is trying to connect so it's failing.
So can anyone help me in suggesting what could be a possible reason for the same?
Error:
[ioredis] Unhandled error event: Error: connect ETIMEDOUT
16|pdsl_pa | at Socket.<anonymous> (/var/www/stage_env/pdsl_parking_service/node_modules/ioredis/built/redis/index.js:318:37)
16|pdsl_pa | at Object.onceWrapper (node:events:645:28)
16|pdsl_pa | at Socket.emit (node:events:526:28)
16|pdsl_pa | at Socket.emit (node:domain:475:12)
16|pdsl_pa | at Socket._onTimeout (node:net:501:8)
16|pdsl_pa | at listOnTimeout (node:internal/timers:559:17)
16|pdsl_pa | at processTimers (node:internal/timers:502:7)
16|pdsl_pa | [ioredis] Unhandled error event: Error: connect EHOSTUNREACH 172.**.***.***:6379
16|pdsl_pa | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
16|pdsl_pa | [ioredis] Unhandled error event: Error: connect EHOSTUNREACH 172.**.***.***:6379
16|pdsl_pa | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
16|pdsl_pa | [ioredis] Unhandled error event: Error: connect EHOSTUNREACH 172.**.***.***:6379

Related

Intermittent redis connection error: 'UNCERTAIN STATE'

Time and time again, we get this error:
{ Error: Redis connection to some-redis-server:6379 failed - read ETIMEDOUT
at TCP.onStreamRead (internal/stream_base_commons.js:171:27) errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'read' }
{ AbortError: Redis connection lost and command aborted. It might have been processed.
at RedisClient.flush_and_error (/usr/src/app/node_modules/redis/index.js:362:23)
at RedisClient.connection_gone (/usr/src/app/node_modules/redis/index.js:664:14)
at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:289:14)
at Object.onceWrapper (events.js:281:20)
at Socket.emit (events.js:193:13)
at TCP._handle.close (net.js:614:12)
code: 'UNCERTAIN_STATE',
command: 'GET'
args: [ 'some-key' ] }
We are using https://www.npmjs.com/package/redis to access redis.
Some details of the setup:
Currently 25GB of data stored in Redis
Writes = a rate of approximately 2MB/sec.
Max number of concurrent clients connected: 400
I don't know where to really start looking, so any help would be appreciated.

MongoDB Atlas connection error "failed to connect to server..."

I am trying to perform a connection to mongodb using mongoose but it throws an error.
Here is my code:
mongoose.connect("mongodb+srv://username:password#cluster0-bocic.mongodb.net/test?retryWrites=true", {useNewUrlParser: true})
.then(()=>console.log("Database connected..."))
.catch(err=>console.log(err));
Here is the error:
[0] { MongoNetworkError: failed to connect to server [cluster0-shard-00-01-bocic
.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to cluster
0-shard-00-01-bocic.mongodb.net:27017 closed]
[0] at Pool.<anonymous> (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mo
ngodb-core\lib\topologies\server.js:431:11)
[0] at Pool.emit (events.js:182:13)
[0] at connect (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mongodb-cor
e\lib\connection\pool.js:557:14)
[0] at callback (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mongodb-co
re\lib\connection\connect.js:109:5)
[0] at runCommand (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mongodb-
core\lib\connection\connect.js:129:7)
[0] at Connection.errorHandler (C:\Users\Med\Desktop\jutsuapp\myapp\node_mod
ules\mongodb-core\lib\connection\connect.js:321:5)
[0] at Object.onceWrapper (events.js:273:13)
[0] at Connection.emit (events.js:182:13)
[0] at TLSSocket.<anonymous> (C:\Users\Med\Desktop\jutsuapp\myapp\node_modul
es\mongodb-core\lib\connection\connection.js:350:12)
[0] at Object.onceWrapper (events.js:273:13)
[0] at TLSSocket.emit (events.js:182:13)
[0] at _handle.close (net.js:610:12)
[0] at TCP.done (_tls_wrap.js:386:7)
[0] name: 'MongoNetworkError',
[0] errorLabels: [ 'TransientTransactionError' ],
[0] [Symbol(mongoErrorContextSymbol)]: {} }
I got to solve the same problem: in the last three days my applications (node.js, express, mongoose, graphql) got connected to the mongoDB (in the cloud) whithout any problem, but today I got:
Error: MongoNetworkError: failed to connect to server [cluster0-shard-00-00-cpkkj.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to cluster0-shard-00-00-cpkkj.mongodb.net:27017 closed]
I verified the IP of my PC and that's it: it has changed and is not more the same IP I added to the Whitelist, so I added the new one and the problem was solved.
If you would like to enable any host connection access, you can set to the whitelist in atlas configuration the following IP address:
0.0.0.0
Then, even when your IP address suddenly changes, you might still connect.

Node.js, ws-tcp-relay with nats: connection error

Please help solve the problem:
When I start the nats server listening 4222 port:
./gnatsd --addr localhost --port 4222, then
./ws-tcp-relay localhost:4222 -p 4223 and try to connect through websockets using websocket-nats like this (in service.js for example):
'use strict';
const nats = require('websocket-nats').connect('ws://localhost:4223');
I get this error:
node server.js
events.js:188
throw err;
^
Error: Unhandled "error" event. (Could not connect to server: Error: getaddrinfo ENOTFOUND localhost:4223 localhost:4223:4223)
at Client.emit (events.js:186:19)
at Socket.<anonymous> (/home/dev/projects/node-pub/node_modules/websocket-nats/lib/nats.js:404:14)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
But, if I try to connect to nats directly using tcp client port 4222, the connection establishes succesfull:
const nats = require('nats').connect('nats://localhost:4222');

MEAN: Unhandled rejection MongoError: not authorized on mean-dev to execute command

I installed meanjs in my OpenSUSE distro, however when I run npm start, here's what I get:
+ Important warning: config.domain is empty. It should be set to the fully qualified domain of the app.
Unhandled rejection MongoError: not authorized on mean-dev to execute command { listIndexes: "sessions", cursor: {} }
at Function.MongoError.create (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/cursor.js:212:36)
at /home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/connection/pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
From previous event:
at MongoStore.setAutoRemoveAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:129:40)
at MongoStore.handleNewConnectionAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:121:18)
at MongoStore (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:96:26)
at Object.module.exports.initSession (/home/tasher/Projects/meanjs_test/config/lib/express.js:120:12)
at Object.module.exports.init (/home/tasher/Projects/meanjs_test/config/lib/express.js:243:8)
at /home/tasher/Projects/meanjs_test/config/lib/app.js:25:23
at /home/tasher/Projects/meanjs_test/config/lib/mongoose.js:35:21
at process._tickCallback (internal/process/next_tick.js:109:7)
Unhandled rejection MongoError: not authorized on mean-dev to execute command { listIndexes: "sessions", cursor: {} }
at Function.MongoError.create (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/cursor.js:212:36)
at /home/tasher/Projects/meanjs_test/node_modules/mongodb-core/lib/connection/pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
From previous event:
at MongoStore.setAutoRemoveAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:129:40)
at MongoStore.handleNewConnectionAsync (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:121:18)
at MongoStore (/home/tasher/Projects/meanjs_test/node_modules/connect-mongo/src/index.js:96:26)
at module.exports (/home/tasher/Projects/meanjs_test/config/lib/socket.io.js:73:20)
at Object.module.exports.configureSocketIO (/home/tasher/Projects/meanjs_test/config/lib/express.js:214:38)
at Object.module.exports.init (/home/tasher/Projects/meanjs_test/config/lib/express.js:258:14)
at /home/tasher/Projects/meanjs_test/config/lib/app.js:25:23
at /home/tasher/Projects/meanjs_test/config/lib/mongoose.js:35:21
at process._tickCallback (internal/process/next_tick.js:109:7)
error: uncaughtException: getaddrinfo ENOTFOUND linux-hcjz.suse date=Mon Aug 28 2017 22:46:50 GMT+0100 (WEST), pid=4497, uid=1000, gid=100, cwd=/home/tasher/Projects/meanjs_test, execPath=/usr/bin/node6, version=v6.11.1, argv=[/usr/bin/node6, /home/tasher/Projects/meanjs_test/server.js], rss=97284096, heapTotal=69029888, heapUsed=48863040, external=20182576, loadavg=[0.6513671875, 0.61669921875, 0.43505859375], uptime=3056
Error: getaddrinfo ENOTFOUND linux-hcjz.suse
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
I have re-installed meanjs twice but in vain. Mongo is also running. By the way:
tasher#linux-hcjz:~/Projects/meanjs_test> node -v
v6.11.1
tasher#linux-hcjz:~/Projects/meanjs_test> npm6 -v
3.10.10
Any thoughts?
try adding execution permission to your mean-dev
chmod 755 path_for_package/mean-dev
replace path path_for_package with your path

UncaughtException: connect ETIMEDOUT in Node JS

Error :
error: uncaughtException: connect ETIMEDOUT date=Wed Jan 14 2015
23:12:29 GMT+0530 (IST), pid=2397, uid=1000, gid=1000,
cwd=/home/user/node/workingcopy/server_dev, execPath=/usr/bin/nodejs,
version=v0.10.33,
argv=[nodejs, /home/user/node/workingcopy/server_dev/app.js], rss=69976064,
heapTotal=63359488, heapUsed=38560856, loadavg=[0.19091796875,
0.4814453125, 0.439453125], uptime=189505.245376888,
trace=[column=11, le=net.js, function=errnoException, line=904,
method=null,
native=false, column=19, file=net.js, function=Object.afterConnect [as
oncomplete], line=895, method=afterConnect [as oncomplete],
native=false], stack=[Error: connect ETIMEDOUT, at errnoException
(net.js:904:11), at Object.afterConnect [as oncomplete]
(net.js:895:19)]
How can we avoid server crash on this exception.?

Resources