When I create an IMAP connection with node-imap module with a Mail-in-a-box (MIAB) email, after a few minutes, I get the ECONNRESET error. I want to know if it is a fault in the connection configuration, or is it from MIAB server side that will disconnect the connection if it has been idle for too long.
Here is my IMAP connection configuration:
{
port: 993,
tls: true,
authTimeout: 30000,
connTimeout: 30000,
keepalive: {
forceNoop: true,
},
tlsOptions: {
rejectUnauthorized: false,
},
}
And this is the error I got:
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
source: 'socket'
}
I am using the mail-notifier module, which is a wrapper of node-imap module. This is the code where I register for events in the IMAP connection
const notifier = Notifier(imap);
notifier
.on("end", () => notifier.start())
.on("connected", () => {
console.log(`Connected IMAP: ${user}`);
})
.on("mail", (mail) => {
this.onMail(mail, user);
})
.on("error", (e: any) => {
console.log(`IMAP error: ${user}, time: ${Date.now()}`);
console.log(e);
setTimeout(() => {
notifier.stop();
notifier.start();
}, 5000);
})
.start();
Related
When I try to connect mongodb with node I get this error.(In picture)
In many tutorial I have seen the solution of the problem can be found by whitelisting the ip address. but trust me I did but nothing happened.
This is my code
const { MongoClient, ServerApiVersion } = require("mongodb");
// async function listDatabases(client){
// databasesList = await client.db().admin().listDatabases();
// console.log("Databases:");
// databasesList.databases.forEach(db => console.log(` - ${db.name}`));
// };
async function main() {
/**
* Connection URI. Update <username>, <password>, and <your-cluster-url> to reflect your cluster.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri =
"mongodb+srv://bran:R8VP2F3ZvEZWRi5l#cluster0.hd6phlm.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
try {
// Connect to the MongoDB cluster
await client.connect();
// Make the appropriate DB calls
await listDatabases(client);
} catch (e) {
console.error("the error: ", e);
} finally {
await client.close();
}
}
main().catch(console.error);
async function listDatabases(client) {
databasesList = await client.db().admin().listDatabases();
console.log("Databases:");
databasesList.databases.forEach((db) => console.log(` - ${db.name}`));
}
This is my code
This is the error I am getting:
MongoServerSelectionError: connect ETIMEDOUT 15.206.14.158:27017
at Timeout._onTimeout (E:\node-mongo-connect\node_modules\mongodb\lib\sdam\topology.js:293:38)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-mg9lmct-shard-00-00.hd6phlm.mongodb.net:27017' => [ServerDescription],
'ac-mg9lmct-shard-00-01.hd6phlm.mongodb.net:27017' => [ServerDescription],
'ac-mg9lmct-shard-00-02.hd6phlm.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-hltwao-shard-0',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
This is the error I am getting
I faced this issue a week ago. When I add my corrent Ip address in the list of network accesses in monogo atles, the issue was fixed. The important thing to mention that the 0.0.0.0 was not working.
I was following the guide here https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-elasticsearch.html for accessing elasticsearch via a curl request and was wondering how I can translate this curl -u "elastic:somepassword" -k "https://quickstart-es-http:9200" to nodejs.
I have this setup but I'm unable to connect:
https.get(
"https://quickstart-es-http:9200",
{ headers: { authorization: "Basic elastic:" + process.env.ES_SECRET } },
(innerRes) => {
let data = "";
innerRes.on("error", (err) => {
console.error("erro>>", err);
});
innerRes.on("data", (chunk) => {
data += chunk;
});
innerRes.on("end", () => {
console.log("data", data);
res.send(data);
});
innerRes.on("close", () => {
console.log("data", data);
res.send(data);
});
}
);
the error message I'm getting is:
Error: connect ECONNREFUSED 10.28.9.116:9200
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:365:28)
at emitErrorNT (node:internal/streams/destroy:193:8)
at emitErrorCloseNT (node:internal/streams/destroy:158:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '10.28.9.116',
port: 9200
}
Thank you!
You can set rejectUnauthorized to false. See more here https://nodejs.org/api/https.html#https_https_request_url_options_callback
const https = require('https');
const options = {
hostname: 'encrypted.google.com',
port: 443,
path: '/',
method: 'GET',
rejectUnauthorized: false
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
Trying to connect to DynamoDB and getting this error
I am trying to use this db to test some Telegram bots but now its not essential, cause i just can't find any information how to fix this problem, mb i am stupid, but...
Code:
var AWS = require("aws-sdk");
let awsConfig = {
"region": "eu-central-1",
"endpoint": "http://dynamodb.eu-central-1.amazonaws.com",
"accessKeyId": "my_access_key",
"secretAccesKey": "my_secret_access_key"
}
AWS.config.update(awsConfig);
let docClient = new AWS.DynamoDB.DocumentClient();
let fetchOneByKey = function ()
{
var params =
{
TableName: "users",
Key: {
"id": 132
}
};
docClient.get(params, function (err, data) {
if(err){
console.log("error: " + JSON.stringify(err, null, 2));
}
else
{
console.log("success: " + JSON.stringify(data, null, 2));
}
})
}
fetchOneByKey();
Tried some solutions from here, but nothing helped
Tried another solution:
let db = new AWS.DynamoDB({apiVersion: '2014-12-04'});
db.listTables({}, function(err, data) { // 2
console.log(data);
console.log(err);
});
Catched this
data:
null
err:
Error: connect ENETUNREACH 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
errno: -4062,
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2021-04-15T23:15:09.312Z,
originalError: {
message: 'Could not load credentials from any providers',
errno: -4062,
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2021-04-15T23:15:09.312Z,
originalError: {
message: 'EC2 Metadata roleName request returned error',
errno: -4062,
code: 'ENETUNREACH',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2021-04-15T23:15:09.312Z,
originalError: [Object]
}
}
}
Whenever the server starts, I see the following console error message:
Server started at: https://localhost:3333
170929/232536.579, [log,connection,client,error] message: socket hang up, stack: Error: socket hang up
at TLSSocket.<anonymous> (_tls_wrap.js:829:25)
at emitOne (events.js:95:20)
at TLSSocket.emit (events.js:182:7)
at Socket.<anonymous> (net.js:484:12)
at Socket.g (events.js:273:16)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at TCP._onclose (net.js:484:12)
I was able to determine that if I removed the tls option from the server.connection, the error disappears.
This is the code in the server
import Hapi from 'hapi';
import inert from 'inert';
import fs from 'fs';
import { apiRoutes } from './api/api-routes';
import { serverConfig } from 'common';
import _ from 'lodash';
const good = require('good');
const server = new Hapi.Server();
const tls = {
key: fs.readFileSync('cert/server-key.pem'),
cert: fs.readFileSync('cert/server-crt.pem'),
ca: fs.readFileSync('cert/ca-crt.pem'),
};
const host = serverConfig.host;
const port = serverConfig.port;
server.connection({
address: '0.0.0.0', // listen on all interfaces!
host,
port,
tls,
});
const options = {
reporters: {
myConsoleReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*' }],
}, {
module: 'good-console',
}, 'stdout'],
myFileReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ ops: '*' }],
}, {
module: 'good-squeeze',
name: 'SafeJson',
}, {
module: 'good-file',
args: ['./hapi.log'],
}],
},
};
server.register([
{
register: inert,
},
{
register: good,
options,
},
],
(err) => {
if (err) {
throw
// define static ui
server.route({
method: 'GET',
path: '/{path*}',
handler: {
directory: {
path: serverConfig.staticAssetsDir,
},
},
});
// start server
server.start(() => {
console.log(`Server started at: ${server.info.uri}`);
});
}
);
What could be the issue, and how could I get started debugging this?
I am trying to create a Kik Messenger bot according to their API using Firebase Cloud Functions. I am using Blaze Plan. I am trying to reply to a message that my bot received. I can receive messages on my API but when I try to reply to them I get an error. An error is not from the request callback. I see the error on Firebase Console.
Error: connect ECONNREFUSED 72.14.246.44:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '72.14.246.44',
port: 443
Requests to the Kik Messenger API works on local and remote node/express app. I tried to use kik-node on Cloud Functions but it gave the same result. What I have discovered so far is that https://auth.kik.com resolves to Amazon and https://api.kik.com resolves to Google Hosting. I think they are also using Firebase Cloud Functions for their API. Can it be possible that they are blocked inbound requests? Here is the sample code of what I tried.
exports.messagepost = functions.https.onRequest((req, res) => {
// Gives the error below
// {
// Error: connect ECONNREFUSED 72.14.246.44:443
// at Object.exports._errnoException (util.js:1018:11)
// at exports._exceptionWithHostPort (util.js:1041:20)
// at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
// code: 'ECONNREFUSED',
// errno: 'ECONNREFUSED',
// syscall: 'connect',
// address: '72.14.246.44',
// port: 443
// }
request.post({
uri: 'https://api.kik.com/v1/message',
body: JSON.stringify({
foo: 'bar'
}),
json: true,
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
},
headers: {
'Content-Type' : 'application/json'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
exports.messageget = functions.https.onRequest((req, res) => {
// Gives the error below
// {
// Error: connect ECONNREFUSED 72.14.246.44:443
// at Object.exports._errnoException (util.js:1018:11)
// at exports._exceptionWithHostPort (util.js:1041:20)
// at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
// code: 'ECONNREFUSED',
// errno: 'ECONNREFUSED',
// syscall: 'connect',
// address: '72.14.246.44',
// port: 443
// }
request.get({
uri: 'https://api.kik.com/v1/message',
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
exports.verificationget = functions.https.onRequest((req, res) => {
// Runs with no errors
request.get({
uri: 'https://auth.kik.com/verification/v1/check',
qs: {
u: 'username',
d: 'hostname',
debug: true
},
body: JSON.stringify({ data: 'debugsigneddata' }),
headers: {
'Content-Type' : 'application/json' ,
'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
},
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
exports.verificationpost = functions.https.onRequest((req, res) => {
// Runs with no errors
request.post({
uri: 'https://auth.kik.com/verification/v1/check',
qs: {
u: 'username',
d: 'hostname',
debug: true
},
body: JSON.stringify({ data: 'debugsigneddata' }),
headers: {
'Content-Type' : 'application/json' ,
'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
},
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
I ran into a similar issue while implementing an OAuth2 token exchange using cloud functions instead of running a dedicated server.
This might not help the OP but to fix this error in my case, I had to add the https:// protocol to my post URL as it was missing.
If others run into this issue it might be worth checking your POST url is written correctly.