When changing the settings inside the new bull Queue object, I get an error in the console. When running Bull Queue locally the application works perfectly fine. As soon as I change the credentials to Azure, I get the error below. When running locally I run the redis-server but not when using the Azure credentials.
I have tried the example tutorial, on the Azure website, with nodejs and the redis npm package, and the Azure redis cache works perfectly fine. Therefore, I am left to believe that I am doing something wrong in the config. I have also tried adding "maxRetriesPerRequest" and "enableReadyCheck" to the redis object however, they have had no effect. I also make sure I execute the done function within the process function.
const queue = new Queue('sendQueue', {
defaultJobOptions: { removeOnComplete: true },
redis: {
port: env.AZURE_REDIS_PORT,
host: env.AZURE_REDIS_HOST,
password: env.AZURE_REDIS_PASSWORD
},
});
at Queue.<anonymous> (/Users/abc/Projects/Sean/dist/tasks/sendQueue.js:47:11)
at Queue.emit (events.js:208:15)
at Redis.emit (events.js:203:13)
at Redis.silentEmit (/Users/abc/Projects/Sean/node_modules/ioredis/built/redis/index.js:482:26)
at Socket.<anonymous> (/Users/abc/Projects/Sean/node_modules/ioredis/built/redis/event_handler.js:122:14)
at Object.onceWrapper (events.js:291:20)
at Socket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:183:27)
Try to add configuration for TLS when using Azure redis cache. Should be the same config value as host. I did not manage to get a connection without it.
var notificationQueue = new Queue('notifications', {
redis: {
port: Number(process.env.REDIS_PORT),
host: process.env.REDIS_HOST,
password: process.env.REDIS_PASS,
tls: {
servername: process.env.REDIS_HOST
}
}});
Related
When I run firebase emulators:start in my project, the command has the following output:
i emulators: Starting emulators: functions, firestore, hosting
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, pubsub, storage
⚠ Your requested "node" version "16" doesn't match your global version "18". Using node#18 from host.
⚠ firestore: Did not find a Cloud Firestore rules file specified in a firebase.json config file.
⚠ firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i firestore: Firestore Emulator logging to firestore-debug.log
i hosting: Serving hosting files from: public
✔ hosting: Local server: http://127.0.0.1:9001
i ui: Emulator UI logging to ui-debug.log
When I open the emulator UI at localhost:4000, I get the a message saying the emulators are disconected:
Emulator UI. Despite this message, the emulators are still running and I can access the hosting at localhost:9001.
Eventually, the emulator command stops with this error message:
Error: TIMEOUT: Port 4000 on localhost was not active within 60000ms
despite the fact that I did open the emulator UI at port 4000.
This is at the top of ui-debug.log:
Web / API server started at localhost:4000
u [FetchError]: request to http://localhost:4400/emulators failed, reason: connect ECONNREFUSED ::1:4400
at ClientRequest.<anonymous> (/Users/patrick/.cache/firebase/emulators/ui-v1.7.0/server.bundle.js:326:16909)
at ClientRequest.emit (node:events:527:28)
at Socket.socketErrorListener (node:_http_client:454:9)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
Sometimes, but not all the time, before stopping it will give this message:
i ui: Stopping Emulator UI
⚠ Emulator UI has exited upon receiving signal: SIGINT
but with no clear explanation.
They've raised this issue on firebase-tools. Specifying host as "127.0.0.1" instead of the default "localhost" also worked for me.
{
"emulators": {
"auth": {
"port": 9099
},
"firestore": {
"port": 8080
},
"hub": {
"host": "127.0.0.1"
},
"ui": {
"enabled": true,
"host": "127.0.0.1"
}
}
}
I have a NodeJS app that works fine when run standalone on a server. When I run it in a docker container it displays the following error message:
ConnectionError: Failed to connect to TEXTREPLACED:undefined - socket hang up
at /app/node_modules/mssql/lib/tedious/connection-pool.js:71:17
at Connection.onConnect (/app/node_modules/tedious/lib/connection.js:1037:9)
at Object.onceWrapper (node:events:514:26)
at Connection.emit (node:events:394:28)
at Connection.emit (/app/node_modules/tedious/lib/connection.js:1065:18)
at Connection.socketError (/app/node_modules/tedious/lib/connection.js:1663:12)
at Connection.socketEnd (/app/node_modules/tedious/lib/connection.js:1693:12)
at Socket. (/app/node_modules/tedious/lib/connection.js:1433:14)
at Socket.emit (node:events:406:35)
at endReadableNT (node:internal/streams/readable:1331:12) {
code: 'ESOCKET',
originalError: ConnectionError: Failed to connect to TEXTREPLACED:undefined - socket hang up
at ConnectionError (/app/node_modules/tedious/lib/errors.js:13:12)
at Connection.socketError (/app/node_modules/tedious/lib/connection.js:1663:56)
at Connection.socketEnd (/app/node_modules/tedious/lib/connection.js:1693:12)
at Socket. (/app/node_modules/tedious/lib/connection.js:1433:14)
at Socket.emit (node:events:406:35)
at endReadableNT (node:internal/streams/readable:1331:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ESOCKET'
}
}
My connection code is:
const sqlConfig = {
user: 'LOGIN',
password: 'PASSWORD',
server: 'SERVER\\INSTANCE',
database: 'DATABASE',
debug:true,
port: 1433,
driver:'tedious',
pool:{
idleTimeoutMillis: 1000
},
options:{
port:1433,
enableArithAbort:true,
encrypt:true,
trustServerCertificate:true,
instanceName:'INSTANCE',
database:'DATABASE',
debug:{
packet: true,
data:true,
payload:true,
token:true,
log:true
}
}
};
const global_pool = new sql.ConnectionPool(sqlConfig);
var global_pool_con = null;
try {
global_pool_con = global_pool.connect();
}catch{
console.log(err);
}
Dockerfile
# Use Node base image
FROM node:latest
#ports
EXPOSE 3000
EXPOSE 1433
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
USER node
CMD [run, script, release]
The "release" script runs the initial js file.
Confusingly the error shows "undefined" instead of a port number. I have used both host and bridge connections with the ports 1433 and 3000 (HAPI) routed and confirmed the ports are exposed in the dockerfile.
Considering that it works when standalone i'm presuming that a docker setting somewhere it's causing the issue.
Update: The TLS/SSL negotiation packet is being sent but is not received
State change: SentPrelogin -> SentTLSSSLNegotiation
Update: The SQL Server is displaying this error in the event logs when the dockerised app attempts to connect.
A fatal alert was generated and sent to the remote endpoint. This may result in termination of the connection. The TLS protocol defined fatal error code is 40. The Windows SChannel error state is 1205.
An TLS 1.2 connection request was received from a remote client application, but none of the cipher suites supported by the client application are supported by the server. The SSL connection request has failed.
Thanks to everyone for your help.
The resolution for this was to update the openSSL.cnf file, it had additional lines in it from the source image that weren't required.
I am testing a nodejs app on GCP functions and a MongoDB instance in GCP cloud run(I know this is not a good idea) but again this is a test. I am able to get the mongo image running on cloud run and I am given a service endpoint as https://mongodb.foo.bar.run.app and I have the container port in this cloud run service as 27017.
When I try and edit the mongoose.connect() method to include this service uri I am not able to connect with the app. I have the mongodb cloud run instance open to receive traffic from all traffic(Again not a good idea), but I still can't get the node app to connect.
I have setup the connection in node as mongoose.connect('mongodb://mongodb.foo.bar.run.app:27017/test');
but I get this error
Error: connect ETIMEDOUT <IP ADDRESS GOES HERE>:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:129:14)
Emitted 'error' event on NativeConnection instance at:
at NativeConnection.Connection.error (/Users/foo/nodejs/bar/node_modules/mongoose/lib/connection.js:443:8)
at /Users/foo/nodejs/bar/node_modules/mongoose/lib/connection.js:472:15
at /Users/foo/nodejs/bar/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21
at /Users/foo/nodejs/bar/node_modules/mongodb/lib/db.js:232:14
at Server.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb/lib/server.js:240:9)
at Object.onceWrapper (events.js:421:26)
at Server.emit (events.js:314:20)
at Pool.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb-core/lib/topologies/server.js:308:68)
at Pool.emit (events.js:314:20)
at Connection.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb-core/lib/connection/pool.js:115:12)
at Object.onceWrapper (events.js:421:26)
at Connection.emit (events.js:314:20)
at Socket.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb-core/lib/connection/connection.js:144:49)
at Object.onceWrapper (events.js:421:26)
at Socket.emit (events.js:314:20)
at emitErrorNT (internal/streams/destroy.js:100:8) {
name: 'MongoError'
}
I tried to curl the service uri as
curl https://mongodb.foo.bar.run.app
and I get a 200 response in the mongo logs GET 200 466B but if I
curl mongodb.foo.bar.run.app
I get a 302 response code GET 302 0B.
I looked at the mongoose documentation but I couldn't figure what I was doing wrong. I know the documentation states user and password on the uri string, but when I run it locally on my docker engine I did not use a user and password and it worked.
As mentioned in the comments, it's not possible to run MongoDB on Cloud Run since as mentioned here:
Cloud Run can only receive HTTP requests or Pub/Sub push events.
Connecting to MongoDB requires a TCP protocol rather than HTTP, that's why every call to it would fail even if the port is reachable.
Cloud Run is in this sense more similar to AWS Lambda than it's to AWS Fargate as it's even billed on a per request basis rather than on resources consumed.
I am trying to connect my SQL Server database with node.js using knex but I am facing issue
Error: No event 'socketConnect' in state 'SentPrelogin'
at Connection.dispatchEvent (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1281:26)
at Connection.socketConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1303:10)
at C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1145:12
at Socket.onConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connector.js:106:7)
at Socket.emit (events.js:314:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1131:10)
Emitted 'error' event on Connection instance at:
at Connection.dispatchEvent (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1281:12)
at Connection.socketConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1303:10)
[... lines matching original stack trace ...]
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1131:10)
[nodemon] app crashed - waiting for file changes before starting...
My code is
var knex = require('knex')({
client: 'mssql',
version:"7_1",
connection: {
user: 'sa',
password: 'Admin#123',
server: 'localhost',
database: 'Demo'
}
});
knex.select("*").from("Country")
.then(function (depts){
depts.forEach((dept)=>{ //use of Arrow Function
console.log({...dept});
});
}).catch(function(err) {
// All the error can be checked in this piece of code
console.log(err);
}).finally(function() {
// To close the connection pool
knex.destroy();
});
You need to add a missing dependency:
npm install --save tedious
As of knex v0.95.0 you'll need to use the tedious library instead of mssql when connecting to an MSSQL database. According to the knex upgrade instructions:
MSSQL driver was completely reworked in order to address the multitude of connection pool, error handling and performance issues. Since the new implementation uses tedious library directly instead of mssql, please replace mssql with tedious in your dependencies if you are using a MSSQL database.
Installing the package above should resolve your issue. I also had to set the encrypt option to false when connecting to my local database to avoid this error:
ConnectionError: Failed to connect to localhost:1433 - self signed certificate
Has anyone encountered below error while connecting to standalone redis server using node js ioredis package?
Below is the error stack trace:
2018-08-16T10:52:18.351869060Z [ioredis] Unhandled error event: Error: connect ETIMEDOUT
2018-08-16T10:52:07.449457296Z at Timer.listOnTimeout (timers.js:207:5)
2018-08-16T10:52:07.449448499Z at tryOnTimeout (timers.js:237:5)
2018-08-16T10:52:07.449439722Z at ontimeout (timers.js:365:14)
2018-08-16T10:52:07.449430834Z at Socket._onTimeout (net.js:339:8)
2018-08-16T10:52:07.449421915Z at Socket.emit (events.js:185:7)
2018-08-16T10:52:07.449413002Z at emitNone (events.js:86:13)
2018-08-16T10:52:07.449403458Z at Socket.g (events.js:291:16)
This is occurring for instantiating only Standalone Redis object in node js. Below is the code I am using,
var publisher = new redis(redisPort, redisHost);
any solution would be highly appreciated.
You can probably try increasing the timeout limit since ioredis has a default timeout value.
Normally we would have it set as,
new Redis({
connectTimeout: 10000
})
In your case, since you have,
var publisher = new redis(redisPort, redisHost);
You will have to edit your code to pass the connectTimeout parameter to be passed accordingly.
Hope this helps.
It's a bit late but can be helpful in the future for somebody else.
const redis = new Redis({
port: <your_redis_port>,
host: <your_redis_hostname>,
connectTimeout: 10000
});
I am using Redis client maintained by Heroku and for some strange reason the Redis credentials have been changed by Heroku, I have been facing the same issue until I double-check the old credentials and the one on Heroku and I realised they were no longer the same then copied the new one from Heroku and pasted it in my .env file and everything is working as expected now!!!