We have ReactJS + NodeJS backend app running in Google GCP App Engine, but what we are experiencing is server down time for few min randomly. We have info Logs and error logs in code almost every api and every major functions and all catch blocks. I have also put global exception catch block
process.on('uncaughtException', (error) => {
Logger.error('--- Exception -----', error);
});
I also have error handler middleware my expressjs
app.use(function(error, req, res, next) {
if (error && error.stack && error.message) {
//cluster.worker.disconnect();
Logger.error('---- Global Exception Handler : error ---- ', error);
}
// Any request to this server will get here, and will send an HTTP
// response with the error message 'woops'
res.json({ status: 'FAIL', message: error.message });
});
but whenever server restarts by itself i don't see any exception in logs, it doesn't even appear in process.on('uncaughtException' block also.
One observation is GCP App engine is auto scaling when there is more traffic, but app is going down whenever there more traffic despite auto scaling is happening.
I want to know how to handle this, how to debug this to identify where exactly the issue is, is the issue is at code level if so why none of the exceptions are caught? or the issue is with GCP?
our production server also goes down many times randomly.
I tried using longjohn and setting NODE_DEBUG environment variable to net to get some hint as suggested in other SO Post
Update 1 :
We Ran Jmeter Performance test to check whether load on server is the main reason, as Rafael Lemos rightly pointed in comment, in our case "The instance exceeds the maximum memory for its configured instance_class" may be the reason behind server going down, with lot of trail and error, when we made minimum no of instances = 2 we are not observing server going down.
However jmeter tests are all running fine but when we do jmeter test as well as manual testing at a time , we are observing Socket Hangup Exception, this crash happens immediately as soon as we start using front end app, where as jmeter tests access our backend app. Both backend and front end are running in same app engine.
Kindly find our observations below
Now question is Why Socket Hangup is coming, when I explored this, I found a solution in some other SO post, to handle socket hangup exception I have put below code in app.js but its not working
app.use((req, res, next) => {
if(res.socket.destroyed) {
console.log('----- socketIsDestroyed-- ', res.socket.destroyed);
res.end();
} else {
console.log('----- socketNotDestroyed-- ', res.socket.destroyed);
next();
}
})
And in Google App Engine Sys logs I see following error log multiple times
GET 503 /readiness_check failReason:"app lameducked"
Update2: my app.yaml file , is issue with resource limits ?
runtime: nodejs
env: flex
automatic_scaling:
min_num_instances: 2
max_num_instances: 5
resources:
cpu: .5
memory_gb: 0.9
disk_size_gb: 10
env_variables:
<Many Environment Variables here>
Update3: when we increased resource limit we are observing frequency of server going down is lesser, updated resource limit are as follows. Is it all because of memory limit issues ?
resources:
cpu: 2
memory_gb: 7.5
disk_size_gb: 10
Logs recorded while Socket hangup exception is as below
A 2021-02-25T05:17:16Z 1|dev_client | Error: socket hang up
A 2021-02-25T05:17:16Z 1|dev_client | at createHangUpError (_http_client.js:323:15)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.socketCloseListener (_http_client.js:364:25)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.emit (events.js:203:15)
A 2021-02-25T05:17:16Z 1|dev_client | at TCP._handle.close (net.js:606:12)
A 2021-02-25T05:17:16Z 1|dev_client | Error: socket hang up
A 2021-02-25T05:17:16Z 1|dev_client | at createHangUpError (_http_client.js:323:15)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.socketCloseListener (_http_client.js:364:25)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.emit (events.js:203:15)
A 2021-02-25T05:17:16Z 1|dev_client | at TCP._handle.close (net.js:606:12)
A 2021-02-25T05:17:16.691Z GET 499 0 B 6 s Firefox 85 /api/volunteercampaigns/6037246c4de6880024f01ff3/prominentVolunteers GET 499 0 B 6 s Firefox 85
A 2021-02-25T05:17:16.700Z GET 499 0 B 6 s Firefox 85 /api/volunteercampaigns/6037246c4de6880024f01ff3/prominentVolunteers GET 499 0 B 6 s Firefox 85
A 2021-02-25T05:17:17Z PM2 | App name:dev_client id:1 disconnected
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] exited with code [0] via signal [SIGINT]
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] starting in -cluster mode-
A 2021-02-25T05:17:17Z PM2 | App name:dev_client id:1 disconnected
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] exited with code [0] via signal [SIGINT]
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] starting in -cluster mode-
A 2021-02-25T05:17:18Z PM2 | App [dev_client:1] online
A 2021-02-25T05:17:18Z PM2 | App [dev_client:1] online
Related
Postgres 14
prisma 2
Azure Database
Faced an error during seeding development DB
remaining connection slots are reserved for non-replication superuser connections
I found that this error is caused by lack of connection pool. After some struggling, I failed.
Here are my tries.
checked session leaks(not found)
increase 'max_connections' value in /etc/postgresql/14/postgresql.conf
reboot DB
reboot local node.js app which uses the remote DB
Full logs are below.
PrismaClientUnknownRequestError:
Invalid `prisma.problem.create()` invocation in
/myproject/api/prisma/seed.ts:448:43
445
446 await Promise.all(
447 problemData.map(async (data) => {
→ 448 const newOne = await prisma.problem.create(
Error in connector: Error querying the database: db error: FATAL: remaining connection slots are reserved for non-replication superuser connections
at RequestHandler.request (/myproject/api/node_modules/#prisma/client/runtime/index.js:49026:15)
at async PrismaClient._request (/myproject/api/node_modules/#prisma/client/runtime/index.js:49919:18)
at async /myproject/api/prisma/seed.ts:448:22
at async Promise.all (index 11)
at async main (/myproject/api/prisma/seed.ts:446:3) {
clientVersion: '3.15.2'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
An error occured while running the seed command:
Error: Command failed with exit code 1: yarn seed
I have tried used pm2 modules and use pm2 logs, early pm2 logs are real time and show me everything console it but from today show only at least 15 lines?( can change this line more or less but not show real time "pm2 logs --lines 1000" show at least 1000 but I want show real time logs )
when run "pm2 logs" showing :
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
C:\Users\user.pm2\pm2.log last 15 lines:
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (D:\wamp64\www...\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (D:\wamp64\www...\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (D:\wamp64\www...\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
Why show this error and how resolve it? and why not showing real time logs for me?
all work done :
kill pm2, restart it, update it, update node modules, flush pm2
Thank's
I'm running a forever script sending data from raspberry pi 3 to azure-iot-hub, using the following,
root#raspberrypi3:~# forever start /home/pi/azure/iam/ble_azure.js
After working for about 1.5 days, I stopped getting messages at auzre-iot-hub, when I checked forever list I got the following:
root#raspberrypi3:~# forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] NWgI /usr/bin/nodejs /home/pi/azure/iam/ble_azure.js 8990 3784 /root/.forever/NWgI.log 0:21:17:38.742
When I checked the log file I get this error message:
/home/pi/azure/iam/node_modules/applicationinsights/AutoCollection/Exceptions.js:27
throw error;
^
NotConnectedError: mqtt.js returned client disconnecting error
at translateError (/home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-translate-error.js:25:11)
at MqttTwinReceiver._handleError (/home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:201:42)
at /home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:64:18
at MqttClient._checkDisconnecting (/home/pi/azure/iam/node_modules/mqtt/lib/client.js:314:7)
at MqttClient.subscribe (/home/pi/azure/iam/node_modules/mqtt/lib/client.js:423:12)
at /home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:62:22
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
error: Forever detected script exited with code: 7
error: Script restart attempt #34
state has changed poweredOn
started scanning
[IoT hub Client] Connect error: mqtt.js returned premature close error
Through the log file, mqtt error keeps happening multiple times and forever handled it successfully, what I can't understand why after 1.5 days, I get this error:
**error: Forever detected script exited with code: 7
error: Script restart attempt #34**
Also why I keep getting such mqtt error, why it keeps disconnecting?
**NotConnectedError: mqtt.js returned client disconnecting error**
Forever --version
v0.15.3
root#raspberrypi3:~# uname -a
Linux raspberrypi3 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
Thanks
If you're using Client.fromConnectionString to instantiate the client object the SDK disconnects and reconnects every 45 minutes to renew the shared access signature token. (it doesn't happen with AMQP that uses a different authentication mechanism). It might be that when re-establishing the connection the client hits this "premature close" error that we've been tracking in this issue.
There are 2 things that could help limit potential errors linked to disconnecting/reconnecting:
Use X509 certificates instead of connection strings to authenticate.
Create a client object using Client.fromSharedAccessSignature and build a long-lived signature that does not require disconnecting and reconnecting as often.
Last but not least, the next release of the SDK (1.2.0) will include a retry/reconnect logic that is way more robust than what was there before. I'll update the issue to point to it when it is released.
I have deployed a Bitnami Parse stack to a Google Cloud VM. This stack is basically Apache running as a proxy, Then a MEAN stack handling parse server and dashboard etc.
Everything appears to be working fine when accessing the dashboard and sending individual CURL requests to test it's all available.
However, there appears to be a fatal flaw in that. When Parse returns one of it's errors e.g.
{"code":101,"error":"Object not found."}
Express sees it as an uncaught exception and dies. Now I realise that it's intentional behaviour (There's enough information out there as to why you don't want to persist after an uncaught exception)
The Bitnami stack uses Forever to run the Parse Server, but as you can see from the logs I will include below, you still run into issues with refused connections.
2016-11-25T11:41:16+00:00 DEBUG (7): {"code":101,"error":"Object not found."}
2016-11-25T11:41:16+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
2016-11-25T11:41:17+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
2016-11-25T11:41:17+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
2016-11-25T11:41:17+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
Meanwhile in the Forever logs:
Error generating response. ParseError { code: 101, message: 'Object not found.' } code=101, message=Object not found.
[object Object]
/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/lib/ParseServer.js:425
throw err;
^
Error: EACCES: permission denied, open '/opt/bitnami/apps/parse/htdocs/logs/parse-server.info.2016-11-25'
at Error (native)
error: Forever detected script exited with code: 7
error: Script restart attempt #1
parse-server running on port 1337
parse-dashboard running on port 4040
So you can see that immediately following a Parse error being returned, The service is unavailable until Forever can restart the Parse Server.
This issue appears that it would affect all users as well, so if one user receives an exception, all users lose connection for a brief period.
So the question is, how should this be properly handled? Is Parse + Express not the way to go about it? Or is there some method of configuring Node or Express to return the API error to the requester, without Express dying (And without having to fall into the trap of using uncaughtException to keep Node alive)
Any help would be much appreciated, thank you
The logs from Forever said it's EACCES error, that means ParseServer couldn't access the log file and not able to write the info log in it.
Error: EACCES: permission denied, open '/opt/bitnami/apps/parse/htdocs/logs/parse-server.info.2016-11-25'
at Error (native)
error: Forever detected script exited with code: 7
error: Script restart attempt #1
parse-server running on port 1337
parse-dashboard running on port 4040
I think you have to change the /opt/bitnami/apps/parse/htdocs/logs with proper permission so that ParseServer can write log files in it.
So I basically wanted to host a mqtt pub/sub-enabled node server on Heroku. These are 2 guides I refer to:
https://github.com/adamvr/MQTT.js and https://gist.github.com/1826931
The mqtt pub/sub worked well when tested on localhost, deployment on heroku was fine, but when I tried testing on Heroku it didn't work
I tried 2 commands to subscribe, both showed the same errors.
Command 1:
mosquitto_sub -p <port> -h <host> -t <topic>
Error 1:
Error: Connection refused
Unable to connect (13).
Command 2:
mqtt_sub <port> <host> <topic>
Error 2:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connect ECONNREFUSED
at errnoException (net.js:670:11)
at Object.afterConnect [as oncomplete] (net.js:661:19)
My main.js (server) code is similar to this one - https://gist.github.com/1826931. The error seems more like a node problem than a mqtt pub/sub problem, and I am new to node, so not quite sure how to debug it. I put in some console.log lines but as expected it didn't print since it's not connected. There is a dyno running node main.js on Heroku fine.
Process State Command
------- ---------- ------------
web.1 up for 35m node main.js
Appreciate any advice on this issue.