API stress test locally got ECONNREFUSED - node.js

I'm doing a stress test to my nodejs app, the test basically send a bulk of requests concurrently, sometimes I got this annoying error:
{ RequestError: Error: connect ECONNREFUSED 127.0.0.1:1234
at new RequestError (/mnt/c/Users/rawhi/Desktop/myCode/backend/api/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/mnt/c/Users/rawhi/Desktop/myCode/backend/api/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/mnt/c/Users/rawhi/Desktop/myCode/backend/api/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/mnt/c/Users/rawhi/Desktop/myCode/backend/api/node_modules/request/request.js:185:22)
at Request.emit (events.js:198:13)
at Request.onRequestError (/mnt/c/Users/rawhi/Desktop/myCode/backend/api/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:198:13)
at Socket.socketErrorListener (_http_client.js:392:9)
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: 'RequestError',
message: 'Error: connect ECONNREFUSED 127.0.0.1:1234',
cause:
{ Error: connect ECONNREFUSED 127.0.0.1:1234
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 1234 }
So the test keeps returning this error for "almost" all the requests, but I still can send requests via postman without any problem.
Can anyone explain me what is the problem here ? and how it can be solved ? like using a queue a proxy or anything else useful ?
Thanks in advance

Related

CloudWatch "UnknownEndpoint" error when running Node/express app to EC2 using Docker

I try to run a node/express app on ec2 using a docker image with this command "sudo docker run -it -p 127.0.0.1:3000:3000 name/app:latest" and I receive the following error:
UnknownEndpoint: Inaccessible host: `logs.us-east-1.amazonaws.com’ at port `undefined’. This service may not be available in the `us-east-1' region.
at Request.ENOTFOUND_ERROR (/usr/app/node_modules/aws-sdk/lib/event_listeners.js:574:46)
at Request.callListeners (/usr/app/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/usr/app/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/usr/app/node_modules/aws-sdk/lib/request.js:686:14)
at error (/usr/app/node_modules/aws-sdk/lib/event_listeners.js:406:22)
at ClientRequest.<anonymous> (/usr/app/node_modules/aws-sdk/lib/http/node.js:99:9)
at ClientRequest.emit (node:events:527:28)
at ClientRequest.emit (node:domain:475:12)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
Emitted ‘error’ event on DerivedLogger instance at:
at DerivedLogger.transportEvent (/usr/app/node_modules/winston/lib/winston/logger.js:639:12)
at CloudWatchTransport.emit (node:events:539:35)
at CloudWatchTransport.emit (node:domain:475:12)
at Relay.<anonymous> (/usr/app/node_modules/winston-aws-cloudwatch/lib/index.js:15:41)
at Relay.emit (node:events:527:28)
at Relay.emit (node:domain:475:12)
at Relay._onError (/usr/app/node_modules/winston-aws-cloudwatch/lib/relay.js:74:12)
at /usr/app/node_modules/winston-aws-cloudwatch/lib/relay.js:53:57
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: ‘UnknownEndpoint’,
region: ‘us-east-1’,
hostname: ‘logs.us-east-1.amazonaws.com’,
retryable: true,
originalError: Error: getaddrinfo EAI_AGAIN logs.us-east-1.amazonaws.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3001,
code: ‘NetworkingError’,
syscall: ‘getaddrinfo’,
hostname: ‘logs.us-east-1.amazonaws.com’,
region: ‘us-east-1’,
retryable: true,
time: 2022-11-17T15:06:46.985Z
},
time: 2022-11-17T15:06:46.985Z
}
AWS AMI: ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20220912
"#aws-sdk/client-cloudwatch-logs": "^3.183.0",
HTTPS is enabled on server
If I clone the repo on ec2 and run it using "pm2 --name appName start npm -- start" it works well.
Can you help me to understand how to fix this problem?
I fixed this problem by using the docker host network with the following flag docker --network host as described here.

Cannot Log In Bixby Studio

Bixby Studio could not contact the authentication system at https://bixbydevelopers.com. Please check the URL url and your internet connection, and try again.
[error] [electron] Unable to fetch valid version from url: https://bixbydevelopers.com/dev/v2/valid-ide-version-range FetchError: request to https://bixbydevelopers.com/dev/v2/valid-ide-version-range failed, reason: unable to verify the first certificate
at ClientRequest. (C:\Users\hung.nv14\AppData\Local\Programs\BixbyStudio\resources\app.asar\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (events.js:322:22)
at ClientRequest.EventEmitter.emit (domain.js:482:12)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:310:20)
at TLSSocket.EventEmitter.emit (domain.js:482:12)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
type: 'system',
errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
Is it possible that you are routing all of your network traffic through a proxy or VPN? If so, can you try without going through them?

Redis disconnects randomly when running on WSL but works perfectly when run on Linux server

I have node.js app that uses Redis as a cache among other things.
When my app is running on my Linux server it works great without any problems. But when I am running it locally on my windows machine through WSL it disconnects randomly but mostly when it idles.
it disconnects with this error:
Emitted 'error' event on RedisClient instance at:
at RedisClient.on_info_cmd (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\index.js:431:14)
at C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\index.js:470:14
at Object.callbackOrEmit [as callback_or_emit] (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\lib\utils.js:89:9)
at Command.callback (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\lib\individualCommands.js:157:15)
at RedisClient.flush_and_error (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\index.js:309:29)
at RedisClient.connection_gone (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\index.js:602:14)
[... lines matching original stack trace ...]
at endReadableNT (node:internal/streams/readable:1307:12) {
code: 'UNCERTAIN_STATE',
command
}
And on rarer times with this error:
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1139:16)
Emitted 'error' event on RedisClient instance at:
at RedisClient.on_error (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\index.js:341:14)
at Socket.<anonymous> (C:\Users\mynam\OneDrive\Desktop\nodeapp\node_modules\redis\index.js:222:14)
at Socket.emit (node:events:379:20)
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:81:21) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}

Problem with reason: connect ECONNREFUSED in Node.js

I'm a beginner in node.js.
I would like to connect with API for training.
I'm behind the company proxy.
I have an api-key: http://numbersapi.com/2000/math?json and I want to connect via node-fetch, but I get an error in console:
Error: { FetchError: request to http://numbersapi.com/2000/math failed, reason: connect ECONNREFUSED 107.170.248.47:80
at ClientRequest.<anonymous> (C:\user\training\Node.js\number_API\node_modules\node-fetch\lib\index.js:1455:11)
at ClientRequest.emit (events.js:193:13)
at Socket.socketErrorListener (_http_client.js:397:9)
at Socket.emit (events.js:193:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
message:
'request to http://numbersapi.com/2000/math failed, reason: connect ECONNREFUSED 107.170.248.47:80',
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED' }
I have set properties in .npmrc:
proxy=http://xxx.xxx.com:8080
https-proxy=http://xxx.xxx.com:8080
registry=https://registry.npmjs.org
To the best of my knowledge node-fetch does does not honor the environment variables or anything defined in .npmrc. You need to explicitly define the proxy.

connect my noSQL(mongoDB) database with my nodeJS project. But it is not working fine

I am trying to connect my nodejs with mongoDB but it is not working fine as the following result below.
**
(node:11776) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your o
wn promise library instead: http://mongoosejs.com/docs/promises.html
{ MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0
.1:27017]
at Pool.<anonymous> (D:\KIT\YEAR II\Project\Nodejs\Vidjot\node_modules\mongodb-core\lib\topologies\server.js:336:3
5)
at emitOne (events.js:116:13)
at Pool.emit (events.js:211:7)
at Connection.<anonymous> (D:\KIT\YEAR II\Project\Nodejs\Vidjot\node_modules\mongodb-core\lib\connection\pool.js:2
80:12)
at Object.onceWrapper (events.js:317:30)
at emitTwo (events.js:126:13)
at Connection.emit (events.js:214:7)
at Socket.<anonymous> (D:\KIT\YEAR II\Project\Nodejs\Vidjot\node_modules\mongodb-core\lib\connection\connection.js
:187:49)
at Object.onceWrapper (events.js:315:30)
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)
name: 'MongoError',
message: 'failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1
:27017]' }
**
Here is my source code
Make sure your mongo server is running # localhost:27017 and you have directories created to store data.
start using this command:
>mongod --port 27017 --dbpath c:\data\db

Resources