gke - redis - connection timeout - node.js

My node js application is throwing a connection timeout in order to connect with Redis instance. I have tried to spin up redis instance as a separate deployment as well as memory store redis instance as well. As a deployment in a pod, I use normal nodeport and tried to access this instance using cluster ip. The ip was in the Config Map.
I tried to ping the ip of memory store as well as cluster ip of redis deployment on gke, from the pod of the node js application, but it did not connect.
As deployment of redis instance also got internal ip: 10.0.231.4
Nothing worked
Memory Store :
gcloud redis instances describe my-redis --region=us-central1
Response:
authorizedNetwork: projects/xxxxx/global/networks/xxxxx
createTime: '2019-09-03T13:39:36.050896298Z'
currentLocationId: us-central1-a
host: 10.0.48.3
locationId: us-central1-a
memorySizeGb: 2
name: projects/xxxxx/locations/us-central1/instances/transact-redis
persistenceIamIdentity: serviceAccount:xxxxxxxxxxx-compute#developer.gserviceaccount.com
port: 6379
redisVersion: REDIS_4_0
reservedIpRange: 10.0.48.0/29
state: READY
tier: BASIC
From cloud shell also, I tried to telnet to 10.0.48.3 on 6379 port. It failed as well.
Here is the log:
2019-09-04 17:20:01.164 CEST at Socket.emit (events.js:209:13)
2019-09-04 17:20:01.164 CEST at emitErrorNT (internal/streams/destroy.js:91:8)
2019-09-04 17:20:01.164 CEST at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
2019-09-04 17:20:01.164 CEST at processTicksAndRejections (internal/process/task_queues.js:77:11) {
2019-09-04 17:20:01.164 CEST errno: 'ETIMEDOUT',
2019-09-04 17:20:01.164 CEST code: 'ETIMEDOUT',
2019-09-04 17:20:01.164 CEST syscall: 'connect',
2019-09-04 17:20:01.164 CEST address: '10.0.48.3',
2019-09-04 17:20:01.164 CEST port: 6379
2019-09-04 17:20:01.164 CEST}
2019-09-04 17:20:06.565 CESTContainer called exit(1).
Any idea how to make it work? Thanks in advance.

Remember that you can connect to your Redis instance from Google Kubernetes Engine clusters that are in the same region and use the same network as your instance.
By the same token, you cannot connect to a Cloud Memorystore for Redis instance from a Google Kubernetes Engine cluster without VPC-native/IP aliasing enabled.
My hypothesis would be that you may either have the cluster on a different zone, not configured your VPC for internal connections, or are on different VPCs. Have you tried this setup to connect Redis to a GKE instance?
Keep me posted on any progress!

Related

Docker container connection to host's Kafka throws : Error: connect ECONNREFUSED 127.0.0.1:9092

I have a nodejs app containerized as a linux container which uses the kafka-node library.
Kafka runs on the host machine which runs windows with:
Zookeeper port : 2181
Kafka broker port : 9092
I run the the nodejs container with the following command:
docker container run --network host --name nm name:1.0
In order to connect with the host's kafka I am using the following command:
client = new kafka.KafkaClient({kafkaHost: "localhost:9092"});
But this throws :
Error: connect ECONNREFUSED 127.0.0.1:9092
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 9092
}
When I change the connect command to :
client = new kafka.KafkaClient({kafkaHost: "host.docker.internal:9092"});
I am getting :
TimeoutError: Request timed out after 30000ms
at new TimeoutError (/usr/src/app/node_modules/kafka-node/lib/errors/TimeoutError.js:6:9)
at Timeout._onTimeout (/usr/src/app/node_modules/kafka-node/lib/kafkaClient.js:491:14)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
message: 'Request timed out after 30000ms'
}
Can someone advise what I am doing wrong ?
UPDATE
When switching to a linux host machine, the above localhost methodology runs just fine .
Same problem here, but I can solve
You must set the environment variable KAFKA_ADVERTISED_HOST_NAME with your domain host.docker.internal:9092 in Kafka broker
My example:
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
hostname: 'kafka-internal.io'
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka-internal.io
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
Now I can connect inside container using kafka-internal.io:9092 :)
Not the best answer but switching to a Linux host should make the first methodology (localhost:IP) run just fine .

Sequelize connection to postgres refused on ubuntu 18.04

I deployed my nodejs 10.16.3 app to ubuntu 18.04 from my win10 PC development. After starting the app with pm2 start /ebs/myapp/index.js on ubuntu, there is an error about sequelize (5.19.1) database connection:
$cat index-error.log
Unable to connect to the database: { SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5433
at connection.connect.err (/ebs/myapp/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:170:24)
at Connection.connectingErrorHandler (/ebs/myapp/node_modules/pg/lib/client.js:174:14)
at Connection.emit (events.js:198:13)
at Socket.reportStreamError (/ebs/myapp/node_modules/pg/lib/connection.js:72:10)
at Socket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'SequelizeConnectionRefusedError',
parent:
{ Error: connect ECONNREFUSED 127.0.0.1:5433
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5433 },
original:
{ Error: connect ECONNREFUSED 127.0.0.1:5433
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5433 } }
The postgres (11.5) is running on the same host and I can access it via command line with success.
pm2 log file also indicates that the nodejs app is listening on port 3000. This app front is a nginx reverse proxy which likely has nothing to do with this error.
Here is the db connection string:
const Sql = require("sequelize");
const db = new Sql('mydb', 'postgres', `${process.env.DB_PASSWORD}`, {
host: 'localhost',
dialect: 'postgres',
port:5433,
} );
Why the sequelize connection is refused?
Update: postgresql log:
$ cat postgresql-11-main.log
2019-10-07 20:24:27.712 UTC [665] postgres#emps ERROR: syntax error at or near "psql" at character 1
2019-10-07 20:24:27.712 UTC [665] postgres#emps STATEMENT: psql
;
ubuntu#:/var/log/postgresql$ cat postgresql-11-main.log.1
2019-10-04 09:10:49.214 UTC [22809] LOG: received fast shutdown request
2019-10-04 09:10:49.221 UTC [22809] LOG: aborting any active transactions
2019-10-04 09:10:49.292 UTC [22809] LOG: background worker "logical replication launcher" (PID 22816) exited with exit code 1
2019-10-04 09:10:49.298 UTC [22811] LOG: shutting down
2019-10-04 09:10:49.435 UTC [22809] LOG: database system is shut down
2019-10-04 09:11:11.561 UTC [1084] LOG: listening on IPv4 address "127.0.0.1", port 5432
2019-10-04 09:11:11.567 UTC [1084] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-04 09:11:11.628 UTC [1096] LOG: database system was shut down at 2019-10-04 09:10:49 UTC
2019-10-04 09:11:11.648 UTC [1084] LOG: database system is ready to accept connections
2019-10-04 09:11:12.196 UTC [1134] [unknown]#[unknown] LOG: incomplete startup packet
2019-10-04 09:11:17.827 UTC [1282] [unknown]#[unknown] LOG: incomplete startup packet
2019-10-04 09:13:42.106 UTC [1084] LOG: received fast shutdown request
2019-10-04 09:13:42.110 UTC [1084] LOG: aborting any active transactions
2019-10-04 09:13:42.114 UTC [1084] LOG: background worker "logical replication launcher" (PID 1102) exited with exit code 1
2019-10-04 09:13:42.115 UTC [1097] LOG: shutting down
2019-10-04 09:13:42.138 UTC [1084] LOG: database system is shut down
2019-10-04 09:13:46.533 UTC [3040] LOG: listening on IPv4 address "127.0.0.1", port 5432
2019-10-04 09:13:46.535 UTC [3040] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-04 09:13:46.566 UTC [3041] LOG: database system was shut down at 2019-10-04 09:13:42 UTC
2019-10-04 09:13:46.577 UTC [3040] LOG: database system is ready to accept connections
2019-10-04 09:13:47.110 UTC [3048] [unknown]#[unknown] LOG: incomplete startup packet
2019-10-04 09:13:52.713 UTC [3082] [unknown]#[unknown] LOG: incomplete startup packet
The logs of your PostgreSQL server say that it is launched at the default port 5432. But in your app you'r trying to connect to 5433.
Try this connection instead:
const Sql = require("sequelize");
const db = new Sql('mydb', 'postgres', `${process.env.DB_PASSWORD}`, {
host: 'localhost',
dialect: 'postgres',
port: 5432, // instead of 5433
} );

Node.js Server not connecting to local mongodb instance

I have a node.js server that tries to connect to mongodb (working with mongoose):
mongoose.connect('mongodb://127.0.0.1:27017/ordry', {useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true}).then(result =>{ // 127.0.0.1:27017
console.log("Successfully connected to db!");
}).catch(error =>{
console.log("Error connecting to the database!")
})
Although mongodb is up and running, the connection fails.
I get the following logs:
Thu Jul 18 13:24:50.124 [initandlisten] options: { dbpath: "/home/pi/mongodb/" }
Thu Jul 18 13:24:50.166 [initandlisten] waiting for connections on port 27017
Thu Jul 18 13:24:50.166 [websvr] admin web console waiting for connections on port 28017
Thu Jul 18 13:25:45.647 [initandlisten] connection accepted from 127.0.0.1:50188
1 (1 connection now open)
Thu Jul 18 13:25:45.742 [conn1] end connection 127.0.0.1:50188 (0 connections now open)
EDIT Logs from Node.js:
[nodemon] starting `node ./server/server.js`
{ MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoError: Server at 127.0.0.1:27017 reports maximum wire version 0, but this version of the Node.js Driver requires at least 2 (MongoDB 2.6)]
at Pool.<anonymous> (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/topologies/server.js:431:11)
at Pool.emit (events.js:198:13)
at connect (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/pool.js:557:14)
at callback (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connect.js:109:5)
at runCommand (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connect.js:140:7)
at Connection.messageHandler (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connect.js:334:5)
at Connection.emit (events.js:198:13)
at processMessage (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connection.js:364:10)
at Socket.<anonymous> (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connection.js:533:15)
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)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
Conclusion
I am a bit unsure why it is not working here - especially as everything worked fine on windows.
I am using Raspbian on my Raspberry Pi 3b+.
Any help would be appreciated.
usually this happens because you didn't start mongod process before you try starting mongo shell.
1) Delete mongod.lock file from C:\Program
Files\MongoDB\Server\4.0\data
2) Start mongod server
In another terminal - start mongo shell
1) mongo
The error message you get:
reports maximum wire version 0, but this version of the Node.js Driver requires at least 2 (MongoDB 2.6)
Is warning you to upgrade your MongoDB version to 2.6 at least, because it's not supported by the drivers used by the wire library which MongoDB depends on.
It seems that the version of MongoDB (2.4) provided by Raspbian is not supported anymore, so the best way to run a MongoDB server os a Raspberry Pi is to install another Linux distribution like Ubuntu or Arch Linux.

Node not connecting to hosted mongodb server, failed to connect to sever on first connect

I have a Godaddy hosted website that I'm trying to have node connect from to my Godaddy Mongo server. I can get it to connect to the hosted server if I run on my mac os localhost with the exact same files.
I'm running a MEAN stack app on my hosted site, and the mongo server is using bitnami.
When I SSH into my godaddy hosted site, then run node server/server.js it gives me the following error:
toldhandyman#a2plcpnl0843 [~/public_html]$ node server/server.js
events.js:163
throw er; // Unhandled 'error' event
^
MongoError: failed to connect to server [45.40.179.118:27017] on
first connect [MongoError: connect ECONNREFUSED 45.40.179.118:27017]
at Pool.<anonymous>
(/home/toldhandyman/public_html/node_modules/mongodb-
core/lib/topologies/server.js:327:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:191:7)
at Connection.<anonymous>
(/home/toldhandyman/public_html/node_modules/mongodb-
core/lib/connection/pool.js:274:12)
at Object.onceWrapper (events.js:293:19)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:194:7)
at Socket.<anonymous>
(/home/toldhandyman/public_html/node_modules/mongodb-
core/lib/connection/connection.js:177:49)
at Object.onceWrapper (events.js:293:19)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at emitErrorNT (net.js:1283:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Thats my main problem I'm having. I've been searching through this site and others for days with no success. My server.js works with my localhost using the server call:
In my config file.
MONGO_URI: 'mongodb://root:<my password here>#45.40.179.118:27017
/told-handyman?authSource=admin',
In my server.js file.
mongoose.connect(mongoURI);
When I use the same code on my hosted site it gave me the previous error
MongoError: failed to connect to server [45.40.179.118:27017] on
first connect [MongoError: connect ECONNREFUSED 45.40.179.118:27017].
The Godaddy server is using Bitnami mongodb. I've tried looking through their docs, godaddy support and many other places. I've tried changing the port to 27018. Editing the file "mongodb.conf" in bitnami#told-handyman:/opt/bitnami/mongodb/mongodb.conf hasn't helped either when working with the lines:
#bind_ip = 127.0.0.1
#bind_ip = 0.0.0.0
port = 27017
I've also tried adding different users for the db, and logging in with those credentials, but that only worked on localhost. I've also tried stopping the server and restarting it a few times.
I've made sure that it does get to the dbpath=/data/db.
Another problem I've noticed is getting mongod to work in my server when I SSH into it. Without running mongod, my localhost connects and works fine with the hosted server. When I run the line in my bitnami mongo server it shows:
bitnami#told-handyman:~$ mongod
2017-04-19T10:56:19.582-0700 I CONTROL [initandlisten] MongoDB
starting : pid=14692 port=27017 dbpath=/data/db 64-bit host=told-
handyman
2017-04-19T10:56:19.583-0700 I CONTROL [initandlisten] db version
v3.4.3
2017-04-19T10:56:19.583-0700 I CONTROL [initandlisten] git version:
f07437fb5a6cca07c10bafa78365456eb1d6d5e1
2017-04-19T10:56:19.583-0700 I CONTROL [initandlisten] allocator:
tcmalloc
2017-04-19T10:56:19.583-0700 I CONTROL [initandlisten] modules: none
2017-04-19T10:56:19.584-0700 I CONTROL [initandlisten] build
environment:
2017-04-19T10:56:19.584-0700 I CONTROL [initandlisten] distarch:
x86_64
2017-04-19T10:56:19.584-0700 I CONTROL [initandlisten]
target_arch: x86_64
2017-04-19T10:56:19.584-0700 I CONTROL [initandlisten] options: {}
2017-04-19T10:56:19.611-0700 E NETWORK [initandlisten] listen():
bind() failed Address already in use for socket: 0.0.0.0:27017
2017-04-19T10:56:19.612-0700 E NETWORK [initandlisten] addr
already in use
2017-04-19T10:56:19.612-0700 E NETWORK [initandlisten] Failed to set
up sockets during startup.
2017-04-19T10:56:19.612-0700 E STORAGE [initandlisten] Failed to set
up listener: InternalError: Failed to set up sockets
2017-04-19T10:56:19.612-0700 I NETWORK [initandlisten] shutdown:
going to close listening sockets...
2017-04-19T10:56:19.612-0700 I NETWORK [initandlisten] shutdown:
going to flush diaglog...
2017-04-19T10:56:19.612-0700 I CONTROL [initandlisten] now exiting
2017-04-19T10:56:19.612-0700 I CONTROL [initandlisten] shutting down
with code:48
bitnami#told-handyman:~$
It works when I run mongod --port 27018, and runs properly on localhost. I'm thinking that getting "mongod" to work right might be part of the problem in having my hosted site connect to my mongo server.
To sum up my problem, I have a Godaddy hosted website that can't connect to my Godaddy cloud Mongo server. I can SSh into both, and have node installed on the hosted site. Also running mongod on the server throws an error, but somehow the server still runs with my localhost without even entering that command.
Does anyone know how to fix this problem of connecting my server.js file through node to my mongo server? Am I missing anything about connecting a hosted website to a hosted server thats different from running both locally?
This is my first question here on SO. Thank you for your time and help.

Getting "Error: failed to connect to tunnel VM" with intern/saucelabs

I'm just starting out with intern/saucelabs. Whenever I try a remote test, I'm getting Error: failed to connect to tunnel VM.
My intern.js has
environments: [
{ browserName: 'firefox', version: '28'},
],
tunnel: 'SauceLabsTunnel',
tunnelOptions: {
username: 'foo',
accessKey: 'xxxxxxxxxxxx-xxxx-xxxx-xxxx-xxxx'
},
Execution log
$ intern-runner config=theintern/intern-sauce.js
Listening on 0.0.0.0:9000
Starting tunnel...
Using no proxy for connecting to Sauce Labs REST API.
**********************************************************
A newer version of Sauce Connect (build 1283) is available!
Download it here:
https://saucelabs.com/downloads/sc-4.3-linux.tar.gz
**********************************************************
Started scproxy on port 44275.
Starting secure remote tunnel VM...
Secure remote tunnel VM provisioned.
Tunnel ID: 6586b9012ca2424b8ecd6bd6970e996c
Secure remote tunnel VM is now: booting
Secure remote tunnel VM is now: running
Remote tunnel host is: maki76026.miso.saucelabs.com
Using no proxy for connecting to tunnel VM.
Establishing secure TLS connection to tunnel...
Cleaning up.
Finished! Deleting tunnel.
Error: failed to connect to tunnel VM.
Error: failed to connect to tunnel VM.
at reject <../../../../../../../usr/lib/node_modules/intern/node_modules/digdug/SauceLabsTunnel.js:353:17>
at readStartupMessage <../../../../../../../usr/lib/node_modules/intern/node_modules/digdug/SauceLabsTunnel.js:381:12>
at <../../../../../../../usr/lib/node_modules/intern/node_modules/digdug/SauceLabsTunnel.js:434:12>
at Array.some <native>
at Socket.<anonymous> <../../../../../../../usr/lib/node_modules/intern/node_modules/digdug/SauceLabsTunnel.js:428:21>
at Socket.EventEmitter.emit <events.js:117:20>
at Socket.<anonymous> <_stream_readable.js:746:14>
at Socket.EventEmitter.emit <events.js:92:17>
at emitReadable_ <_stream_readable.js:408:10>
at emitReadable <_stream_readable.js:404:5>
In case it's significant, I'm currently on the free tier.
Some of the most common issues folks run into with Sauce Connect are related to firewall and proxy settings. Please ensure that 443 is open between Sauce Connect and *.saucelabs.com. If a proxy server is used to route traffic on your network Sauce Connect supports proxy servers by passing the --pac or –p flag.
Please download the latest version of Sauce Connect from https://docs.saucelabs.com/reference/sauce-connect/ and start the client with all the necessary flags (a full list is available on the aforementioned page). If this version does not work please start Sauce Connect passing the -v flag, this will generate a verbose log file which will help Sauce Labs diagnose connectivity issues.

Resources