Error: Exceeded maximum number of retries allowed - node.js

A Firebase project in production that has been working fine for over a year, suddenly starts throwing errors after updating dependencies to latest:
firebase-admin
from: ^9.2.0
to: ^11.5.0
firebase-functions
from: ^3.21.2
to: ^4.2.0
Errors like:
Error: Exceeded maximum number of retries allowed. at QueryWatch.<anonymous> (/workspace/app/orders/makeOrderDone.function.js:179:27) at QueryWatch.closeStream (/workspace/node_modules/#google-cloud/firestore/build/src/watch.js:226:18) at /workspace/node_modules/#google-cloud/firestore/build/src/watch.js:335:18 at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:95:5)
and before that error in same log:
Error: A backoff operation is already in progress. at QueryWatch.<anonymous> (/workspace/app/orders/makeOrderDone.function.js:169:35) at QueryWatch.closeStream (/workspace/node_modules/#google-cloud/firestore/build/src/watch.js:226:18) at /workspace/node_modules/#google-cloud/firestore/build/src/watch.js:335:18 at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:95:5) at runNextTicks (internal/process/task_queues.js:64:3) at processTimers (internal/timers.js:497:9)
To give you more context, updating the dependencies was done so I could use the preferRest option.
I added a few comments here https://github.com/firebase/firebase-admin-node/pull/1901
In the time being, I have disabled preferRest, but the errors above won't go.
UPDATE:
related code block:
db
.collection("Orders")
.doc(orderId)
.collection("Order_Items")
.where("order_status_val", "==", 1)
.onSnapshot(() => {
// logic and another onSnapshort query nested here
})

Related

UnhandledPromiseRejectionWarning: MongooseError: Connection 0 was disconnected when calling `startSession

I'm working with MongoDB to save data using transactions.But its giving the below error.
(node:29448) UnhandledPromiseRejectionWarning: MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession (D:\Rubix\rubixkyc\node_modules\mongoose\lib\connection.js:565:31)
at D:\Rubix\rubixkyc\server\util\route_utils.js:35:38
at new Promise (<anonymous>)
at saveKycData (D:\Rubix\rubixkyc\server\util\route_utils.js:32:12)
at D:\Rubix\rubixkyc\server\controllers\bulk_gst_verification_controller.js:48:19
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
[RUBIX KYC] 27-12-2022 07:44:37.193 PM [info]: <server\controllers\bulk_gst_verification_controller.js:46> saving GST verification data ....
(node:29448) MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession (D:\Rubix\rubixkyc\node_modules\mongoose\lib\connection.js:565:31)
at D:\Rubix\rubixkyc\server\util\route_utils.js:35:38
at new Promise (<anonymous>)
at saveKycData (D:\Rubix\rubixkyc\server\util\route_utils.js:32:12)
at D:\Rubix\rubixkyc\server\controllers\bulk_gst_verification_controller.js:48:19
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:29448) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
Sharing the image of the code snippet.
Note:- This started happening after i started using worker pool for concurrency.
This save method i
const workerpool = require('workerpool');
Please help me with the issue

I have just started to use nats with my NestJs Microservices, after npm i nats and recompiling my app I receive this error "stream.on"

This is the error in my cmd window after trying to run a npm start
C:\Users\Desktop\app\ms-users\node_modules\#nestjs\microservices\server\server-nats.js:85
stream.on(constants_1.ERROR_EVENT, (err) => this.logger.error(err));
^
TypeError: stream.on is not a function
at ServerNats.handleError (C:\Users\Desktop\app\ms-users\node_modules\#nestjs\microservices\server\server-nats.js:85:16)
at ServerNats.listen (C:\Users\Desktop\app\ms-users\node_modules\#nestjs\microservices\server\server-nats.js:22:14)
at C:\Users\Desktop\app\ms-users\node_modules\#nestjs\microservices\nest-microservice.js:86:51
at new Promise (<anonymous>)
at NestMicroservice.listenAsync (C:\Users\Deskto\app\ms-users\node_modules\#nestjs\microservices\nest-microservice.js:86:16)
at processTicksAndRejections (node:internal/process/task_queues:93:5)

discord.js client.off fails

I want to reload the code used for events in discord.js. The code is currently stored in a collection (the same way as commands in the discord.js guide). I have the following code:
client.events.delete(args[0]);
const file = require(`../events/${args[0]}.js`);
client.off(file.name, (...eventArgs) => this.events.get(file.name).run(this.client, this.shared, ...eventArgs));
message.reply(`Removed ${file.name} event.`);
The events are added to the listener using this:
for (const file of readdirSync('./events').filter(check => check.endsWith('.js'))) {
const event = require(`./events/${file}`);
this.shared.logger.log('info', `Loaded event ${event.name}`);
this.shared.events.set(event.name, event);
}
this.events.forEach(event => {
const file = require(`./events/${event.name}.js`);
this.client.on(file.name, (...eventArgs) => this.events.get(file.name).run(this.client, this.shared, ...eventArgs));
});
This runs without error, then when the event that was removed is triggered I get the following error in console:
TypeError: Cannot read property 'run' of undefined
at Client.<anonymous> (E:\Files\code\bot\index.js:85:73)
at Client.emit (events.js:315:20)
at WebSocketManager.debug (E:\Files\code\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:125:17)
at WebSocketShard.debug (E:\Files\code\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:168:18)
at WebSocketShard.sendHeartbeat (E:\Files\code\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:557:10)
at Timeout._onTimeout (E:\Files\code\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:529:73)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
I assume this is caused because client.off isn't removing the event from the listener, but is deleting it from the collection, meaning that it is undefined when that event is triggered and the error is caused.
Discord event is always on. If you try to remove it, it will still persist until you've terminated the program, so you'd get the error. Try using this.client.once instead, and recall it when the desired event is needed.

Line number error does not show up when using MSSQL Node?

I have been using MySQL database with Nodejs for a while. I recently switched to MSSQL with Nodejs
When using a try catch block with Nodejs and Mysql any error with the query execution would give me the line at which the error occured
So while using MySQL I did:
try{
await pool.quer(`sql statement`)
}
catch(err){
console.log(err)
}
This would give me an error and the line number of error. But with node-mssql, I get:
{ RequestError: Incorrect syntax near 'Invalid'.
at StreamEvents.req.once.err (C:\Users\David\Main Web\node_modules\mssql\lib\msnodesqlv8\request.js:463:17)
at Object.onceWrapper (events.js:277:13)
at StreamEvents.emit (events.js:189:13)
at errors.forEach.err (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:33:20)
at Array.forEach (<anonymous>)
at routeStatementError (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:26:14)
at invokeObject.end (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:258:13)
at freeStatement (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\driver.js:160:13)
at cppDriver.freeStatement (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\driver.js:150:11)
code: 'EREQUEST',
originalError:
{ Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'Invalid'. sqlstate: '42000', code: 102 },
name: 'RequestError',
number: 102,
state: undefined }
This is such an unhelpful error. I know where the error is coming from for this error because there is only one sql statement getting executed right now but as my program grows without knowing where the error is coming from it will be hard to debug. Is this an expected behavior of node-mssql?
If you see the documentation here, it clearly mentions what it return in error and what not.
It clearly mentions that "Those errors are initialized in node-mssql module and its original stack may be cropped. You can always access original error with err.originalError"
In your catch block you can try printing the stack trace. That should give you the line number where the error occurred. You can use one of the following statements:
console.stack("---TRACE---")
OR
var stackTrace = new Error().stack
console.log(stackTrace)

how to fix: 'MongoError: authentication fail' #MongoDB Atlas

I am connecting to MongoDB Atlas and getting authentication fail error.
that is my connection string:
mongodb://user:<password>#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
That is what I get:
------------------------------------------------
Mongoose connection "error" event fired with:
{ MongoError: authentication fail
at Function.MongoError.create (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:31:11)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/replset.js:1245:38
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:760:7
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:736:20
at finish (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:168:16)
at handleEnd (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:178:7)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:269:11
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:469:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017',
err: [Error] },
{ name: 'mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017',
err: [Error] } ] }
Error: KeystoneJS (Keystone Demo) failed to start - Check that you are running `mongod` in a separate process.
at NativeConnection.<anonymous> (/mnt/c/WEB/keystone-md2/node_modules/keystone/lib/core/openDatabaseConnection.js:62:10)
at NativeConnection.emit (events.js:189:13)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/lib/connection.js:824:17
at connectCallback (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:527:5)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:459:13
at process._tickCallback (internal/process/next_tick.js:61:11)
You have to put your user and password in your connection uri string
mongodb://***'your user':' here comes password '***#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
e.g
mongodb://dbuser:dbpassword#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
The problem is I was leaving <> in connection string. You have to remove those for authentication to work.
I was facing this issue too. But after an hour I came to know that I used the process.env variables for username and password. And also declared them in the .env file. But I forgot to configure dotenv package in my code.
So make sure you didn't make this kind of silly mistake.
For more info go through this documentation of node repositories.
https://www.npmjs.com/package/dotenv
I have a similar error but with connecting to the new Atlas database. Even though I have definitely setup the username and password correctly as stated here and in the documentation (obviously i replaced PASSWORD with my correct MLAB password:
var mongoURI = 'mongodb+srv://heroku_3kcdl3j9:PASSWORD#cluster-3kcdl3j9.auof1.mongodb.net/heroku_3kcdl3j9?retryWrites=true&w=majority';
I have migrated my database from MLAB to Atlas successfully set the correct Network access settings to 0.0.0.0 IP addresss. Setup the environment variable in Heroku. But still get this error:
{ MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'cluster-3kcdl3j9-shard-00-01.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-00.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-02.auof1.mongodb.net:27017',
err: [MongoError] } ],
[Symbol(mongoErrorContextSymbol)]: {} }
(node:47015) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 's' of undefined
at Admin.buildInfo (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb/lib/admin.js:100:37)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/index.js:95:13
at $initialConnection.then.err (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongoose/lib/connection.js:556:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:47015) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:47015) UnhandledPromiseRejectionWarning: MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I had a similar error and in my case, the problem was I have added (whitelisted) a wrong IP address in "IP Access List" on "Security -> Network Access" page.

Resources