Cannot access Mongodb Atlas using my PC IP address - node.js

I'm getting the following error
{ MongoNetworkError: connection 4 to ****cluster******** closed
at TLSSocket.<anonymous> (C:\Users\CITY TECH\Documents\Projects\Cliserve\cliserve-api\node_modules\mongodb-core\lib\connection\connection.js:276:9)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:203:15)
at _handle.close (net.js:606:12)
at TCP.done (_tls_wrap.js:388:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
After adding my IP address to the MongoDB Atlas whitelist for privacy reasons.
I input my IP address by clicking the Add you IP address- it's same as the https://whatismyipaddress.com/ result-
I turned off the firewall and not proxy server exists
Any Idea why this error occurred?

Related

Not able to connect my service with Redis

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

mysql2 connection.connect() hangs in typescript jest test on macOS

I am trying to create a mysql2 connection to a local mysql-Database in a jest-Test on macOS using typescript. And the call to connect() hangs.
Environment:
MacOS: High Sierra (10.13.6)
MySQL: 8.0.18
Typescript: 3.7.2
mysql2: 2.0.1
nodejs: v10.16.3
I am using the promise-Wrapper. The code looks like this:
import { createConnection, ConnectionOptions, Connection } from 'mysql2/promise'
...
async openConnection(options: ConnectionOptions): Promise<Connection> {
console.log('About to create mysql connection using options ', options);
const connection = await createConnection(options);
console.log('Connection created => about to call connect()');
await connection.connect();
console.log('Connection created => connect() returned'); // this line is never reached!
....
return connection;
}
I already added the debug-Option and this is the output:
Dieters-MBP-6:db-typescript rehdie$ node_modules/.bin/jest src/tests/mysql/mysql-connection.spec.ts --testNamePattern="Should open connection"
console.log src/lib/mysql/driver/mysql-driver.ts:21
About to create mysql connection using options { user: 'mysql-test',
password: '1q2w3e4r',
host: 'localhost',
port: 3306,
database: 'mysql_test_db',
charset: 'latin1_swedish_ci',
connectTimeout: 5000,
debug: true }
console.log node_modules/mysql2/lib/connection.js:425
Add command: ClientHandshake
console.log node_modules/mysql2/lib/connection.js:381
raw: 0a382e302e31380018000000277919626469296e00ffffff0200ffc715000000000000000000006d6335316a3c3d454220053a0063616368696e675f736861325f70617373776f726400
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 undefined ==> ClientHandshake#unknown name(0,,78)
console.log node_modules/mysql2/lib/commands/client_handshake.js:96
Server hello packet: capability flags:3355443199=(long password, found rows, long flag, connect with db, no schema, compress, odbc, local files, ignore space, protocol 41, interactive, ssl, ignore sigpipe, transactions, reserved, secure connection, multi statements, multi results, ps multi results, plugin auth, connect attrs, plugin auth lenenc client data, can handle expired passwords, session track, deprecate eof, ssl verify server cert, remember options)
console.log node_modules/mysql2/lib/commands/client_handshake.js:41
Sending handshake packet: flags:11203535=(long password, found rows, long flag, connect with db, odbc, local files, ignore space, protocol 41, ignore sigpipe, transactions, reserved, secure connection, multi results, plugin auth, plugin auth lenenc client data, session track)
console.log node_modules/mysql2/lib/connection.js:253
0 24 <== ClientHandshake#unknown name(1,,104)
console.log node_modules/mysql2/lib/connection.js:257
0 24 <== 64000001cff3aa00000000000800000000000000000000000000000000000000000000006d7973716c2d746573740014a13dd11599725225bcae39464cc3700a5fa085fc6d7973716c5f746573745f6462006d7973716c5f6e61746976655f70617373776f726400
console.log node_modules/mysql2/lib/connection.js:381
raw: fe63616368696e675f736861325f70617373776f726400277919626469296e6d6335316a3c3d454220053a00
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 24 ==> ClientHandshake#unknown name(2,,48)
console.log node_modules/mysql2/lib/connection.js:253
0 24 <== ClientHandshake#unknown name(3,,36)
console.log node_modules/mysql2/lib/connection.js:257
0 24 <== 20000003374930d53dd94bc2dbe6b54e4b83cd628658a1984656eb6ee4f31d7df596ce36
console.log node_modules/mysql2/lib/connection.js:381
raw: 0103
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 24 ==> ClientHandshake#unknown name(4,,6)
console.log node_modules/mysql2/lib/connection.js:381
raw: 000000024000000010010e0d6d7973716c5f746573745f6462
console.error console.js:274
Trace:
at Connection.handlePacket (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:387:17)
at PacketParser.Connection.packetParser.p [as onPacket] (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.Connection.stream.on.data (/Users/rehdie/development/projects/db-typescript/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
console.log node_modules/mysql2/lib/connection.js:395
0 24 ==> ClientHandshake#unknown name(5,maybeOK,29)
console.log src/lib/mysql/driver/mysql-driver.ts:24
Connection created => about to call connect()
RUNS src/tests/mysql/mysql-connection.spec.ts
When I perform a show process list in mysql, I see a new process with Command 'Sleep' (state is empty and info is null).
Any ideas?
You need to ensure that node is using the system time and not fake timers. Add the below line immediately after your imports in the test file
jest.useRealTimers();
Or better still you can set timers to real in your jest config
"timers":"real"

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');

Resources