Heroku | Node.js | Exception when debugging remotely - node.js

I have express.js REST API server on Heroku.
I am trying to debug an error remotely. But, I receive below exception. The steps I tried to debug remote server are mentioned after this exception section.
Can someone please help me how can I debug remote node.js/express.js server?
The exception I receive:
events.js:291
throw er; // Unhandled 'error' event
^
Error: connection not allowed by ruleset
at Parser._onData (/usr/local/Cellar/heroku/7.47.11/lib/client/7.59.1/node_modules/#heroku/socksv5/lib/client.parser.js:122:21)
at Socket.Parser.__onData (/usr/local/Cellar/heroku/7.47.11/lib/client/7.59.1/node_modules/#heroku/socksv5/lib/client.parser.js:33:10)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Emitted 'error' event on Client instance at:
at Parser.<anonymous> (/usr/local/Cellar/heroku/7.47.11/lib/client/7.59.1/node_modules/#heroku/socksv5/lib/client.js:132:10)
at Parser.emit (events.js:314:20)
at Parser._onData (/usr/local/Cellar/heroku/7.47.11/lib/client/7.59.1/node_modules/#heroku/socksv5/lib/client.parser.js:126:16)
at Socket.Parser.__onData (/usr/local/Cellar/heroku/7.47.11/lib/client/7.59.1/node_modules/#heroku/socksv5/lib/client.parser.js:33:10)
[... lines matching original stack trace ...]
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
code: 'EACCES'
}
This is what I am trying:
On my local Terminal, I run heroku ps:forward 9229 --app MY_EXPRESS_APP command.
On my local Visual Code, I have the below launch.json configuration. I tried with both the configurations mentioned in it. (I understand I need only one. But I checked other Stackoverflow articles. So, I tried both the suggestions).
"configurations": [
{
"address": "TCP/IP address of process to be debugged",
"localRoot": "${workspaceFolder}",
"name": "ONE: Attach to Remote",
"port": 9229,
"remoteRoot": "/app",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "attach",
"name": "TWO: Remote Heroku: Debug Remote Server",
"address": "localhost",
"port": 9229,
"protocol": "inspector",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
]
I try to run below command. When I start Debug with above one of configuration... the debugger tries to connect and pauses. And, after 2 or 3 minutes, I see the above exception on Terminal under this command.
$ heroku ps:forward 9229 --app MY_EXPRESS_APP
heroku ps:forward 9229 --app MY_EXPRESS_APP
Establishing credentials... done
SOCKSv5 proxy server started on port 1080
Listening on 9229 and forwarding to web.1:9229
Use CTRL+C to stop port fowarding

Related

Firebase Emulator - UI says emulators disconnected, command times out after 60 seconds

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"
}
}
}

Can not connect docker hosted SSMS from containerized GraphQL api

I am using SQL Server image as DB and trying to connect it with GraphQL api written using TypeORM. If I run docker-compose up -d it is simply runs the DB(I can connect it from local SSMS) but API is not able to connect it.
Dockerfile:
FROM node:14
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Copy app source code
COPY . .
#Expose port and start application
EXPOSE 4000
CMD [ "npm", "run", "dev" ]
Docker-Compose File:
version: "2"
services:
server:
build: .
ports:
- "4000:4000"
depends_on:
- plhdashboardb
plhdashboardb:
container_name: plhdashboardb
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- "1434:1433"
environment:
SA_PASSWORD: "I_AM_mr_React"
ACCEPT_EULA: "Y"
Building it using docker build -t server . and running it using docker-compose up -d
If I try to run the URL http://localhost:4000/graphql, it never loads, but Server can be connected from local SSMS.
ormconfig.json:
{
"type": "mssql",
"host": "plhdashboardb",
"username": "sa",
"password": "I_AM_mr_React",
"database": "plhdashboardb_Dev_Mock",
"synchronize": true,
"autoSchemaSync": true,
"logging": false,
"options": {
"encrypt": true,
"enableArithAbort": true
},
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
},
"seeds": [
"src/database/seeds/**/*{.ts,.js}"
],
"factories": [
"src/database/factories/**/*{.ts,.js}"
]
}
If I enter the container docker exec -it server_server_1 bash and run npm run dev and getting this error:
(node:167) UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to localhost:1434 - Could not connect (sequence)
at Connection.<anonymous> (/usr/src/app/node_modules/mssql/lib/tedious/connection-pool.js:68:17)
at Object.onceWrapper (events.js:422:26)
at Connection.emit (events.js:315:20)
at Connection.EventEmitter.emit (domain.js:467:12)
at Connection.socketError (/usr/src/app/node_modules/mssql/node_modules/tedious/lib/connection.js:1290:12)
at /usr/src/app/node_modules/mssql/node_modules/tedious/lib/connection.js:1116:21
at SequentialConnectionStrategy.connect (/usr/src/app/node_modules/mssql/node_modules/tedious/lib/connector.js:87:14)
at Socket.onError (/usr/src/app/node_modules/mssql/node_modules/tedious/lib/connector.js:100:12)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:467:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:167) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:167) [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.
[nodemon] clean exit - waiting for changes before restart

NODE JS - Client network socket disconnected before secure TLS connection was established

I'm facing an error on running the node script which generates the PayPal invoices using SDK and when it runs from the local server it is working fine but when it runs on production server it is giving below error:
Uncaught Exception
{
"errorType": "Error",
"errorMessage": "Client network socket disconnected before secure TLS connection was established",
"code": "ECONNRESET",
"path": null,
"host": "api.paypal.com",
"port": 443,
"stack": [
"Error: Client network socket disconnected before secure TLS connection was established",
" at TLSSocket.onConnectEnd (_tls_wrap.js:1095:19)",
" at Object.onceWrapper (events.js:286:20)",
" at TLSSocket.emit (events.js:203:15)",
" at TLSSocket.EventEmitter.emit (domain.js:448:20)",
" at endReadableNT (_stream_readable.js:1145:12)",
" at process._tickCallback (internal/process/next_tick.js:63:19)"
]
}
Version Details:
Node Js 10.x, TLS: 1.0
Did anybody face such errors?
"host": "api.paypal.com",
TLS: 1.0
PayPal requires TLS 1.2 https://developer.paypal.com/docs/api/info-security-guidelines/#usetls12
If that was a typo in your question and you are actually using 1.2, then you'll have to debug it more deeply.

Cannot configure Hyperledger Composer with multiuser authetication

I am following the tutorial Using Google OAUTH2.0 with a REST server (https://hyperledger.github.io/composer/latest/tutorials/google_oauth2_rest). After login with success into my Google account, I get this error on the browser:
{
"error": {
"statusCode": 500,
"name": "InternalOAuthError",
"message": "Failed to obtain access token",
"oauthError": {
"errno": "ENOTFOUND",
"code": "ENOTFOUND",
"syscall": "getaddrinfo",
"hostname": "accounts.google.com",
"host": "accounts.google.com",
"port": 443
},
"stack": "InternalOAuthError: Failed to obtain access token\n at Strategy.OAuth2Strategy._createOAuthError (/home/composer/node_modules/passport-oauth2/lib/strategy.js:379:17)\n at /home/composer/node_modules/passport-oauth2/lib/strategy.js:166:45\n at /home/composer/node_modules/oauth/lib/oauth2.js:191:18\n at ClientRequest.<anonymous> (/home/composer/node_modules/oauth/lib/oauth2.js:162:5)\n at emitOne (events.js:116:13)\n at ClientRequest.emit (events.js:211:7)\n at TLSSocket.socketErrorListener (_http_client.js:387:9)\n at emitOne (events.js:116:13)\n at TLSSocket.emit (events.js:211:7)\n at emitErrorNT (internal/streams/destroy.js:66:8)\n at args.(anonymous function) (/home/composer/.npm-global/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:138:29)\n at _combinedTickCallback (internal/process/next_tick.js:139:11)\n at process._tickDomainCallback (internal/process/next_tick.js:219:9)"
}
}
I am behind a corporate proxy. So, I suspect there it is the problem but I am not sure.
Following the tutorial instructions, I edited the file Dockerfile for adding npm configuration of the proxy (ip and port with the right data):
FROM hyperledger/composer-rest-server
RUN npm config set proxy http://ip:port && npm config set https-proxy http://ip:port && \
npm install --production loopback-connector-mongodb passport-google-oauth2 request https-proxy-agent && \
npm cache clean --force && \
ln -s node_modules .node_modules
Also, and I added request and https-proxy-agent modules for implementing the workaround explaining here: Use Passport.js Behind Corporate Firewall for Facebook Strategy, but with no success.
I built the Docker image composer-rest-server like this:
docker build -t myorg/composer-rest-server --build-arg http_proxy=http://ip:port --build-arg https_proxy=http://ip:port .
When I ran the Docker container, this was the log:
[2018-09-28T10:48:18.240Z] PM2 log: Launching in no daemon mode
[2018-09-28T10:48:18.318Z] PM2 log: Starting execution sequence in -fork mode- for app name:composer-rest-server id:0
[2018-09-28T10:48:18.325Z] PM2 log: App name:composer-rest-server id:0 online
WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
Discovering types from business network definition ...
(node:15) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Discovering the Returning Transactions..
Discovered types from business network definition
Generating schemas for all types in business network definition ...
Generated schemas for all types in business network definition
Adding schemas for all types to Loopback ...
Added schemas for all types to Loopback
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
And, after login to my Google account, this was the log:
Unhandled error for request GET /auth/google/callback?code=4%2FbAC3w3UnnALN4kKQD8RdjfC_wrXJeFAojIHKOANISGWYn-zvIzTeO24P96T_SaJDhVBPcbdqrmLxUyv9IajeYrg&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.profile.agerange.read+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.profile.language.read+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile: InternalOAuthError: Failed to obtain access token
at Strategy.OAuth2Strategy._createOAuthError (/home/composer/node_modules/passport-oauth2/lib/strategy.js:379:17)
at /home/composer/node_modules/passport-oauth2/lib/strategy.js:166:45
at /home/composer/node_modules/oauth/lib/oauth2.js:191:18
at ClientRequest. (/home/composer/node_modules/oauth/lib/oauth2.js:162:5)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:66:8)
at args.(anonymous function) (/home/composer/.npm-global/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:138:29)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
And this is COMPOSER_PROVIDERS variable, with the right clientID and clientSecret values:
COMPOSER_PROVIDERS='{
"google": {
"provider": "google",
"module": "passport-google-oauth2",
"clientID": "REPLACE_WITH_CLIENT_ID",
"clientSecret": "REPLACE_WITH_CLIENT_SECRET",
"authPath": "/auth/google",
"callbackURL": "/auth/google/callback",
"scope": "https://www.googleapis.com/auth/plus.login",
"successRedirect": "/",
"failureRedirect": "/"
}
Anyone could tell me where is the problem?
Thanks.
PD: Sorry for this brick!

"npm start" command not working while launching Enketo

I have done enketo-express installtion while launching enkto it shows below error. I'm using this command to launch enketo "npm start"
AbortError: Ready check failed: Redis connection lost and command aborted. It might have been processed.
at RedisClient.flush_and_error (enketo-express/node_modules/redis/index.js:362:23)
at RedisClient.connection_gone (enketo-express/node_modules/redis/index.js:664:14)
at Socket. (enketo-express/node_modules/redis/index.js:293:14)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Worker 7873 sadly passed away. It will be reincarnated.
Note: Following this doc step no: 7
check netstat -ntlp
which port is using 8005
or in some case something running on port 6380
"cache": {
"host": "127.0.0.1",
"port": "6379", # change port from 6380
"password": null
}
Also Different Node version too causes similar problems. Use node version as described in readme
https://github.com/kobotoolbox/enketo-express/issues/528

Resources