Random REARMING DISCONNECT > Connect > Repeat > Crash

Using Raspberry Pi and node.js my app, (apparently) while idle throws REARMING DISCONNECT message followed by repeated connecting and connected disconnect messages then crashes.

The app will run for hours to more than five days error free. I issues no more than two requests every thirty seconds. There is another app running on a second RPi connected via sockets that logs activity.

I could really use events telling my app that REARMING is in process and FAILED or COMPLETED if there is not an internal fix for this.

Here is an excerpt from the console log.

Connecting to: blynk-cloud.com 8441
SSL
authorization...
Connected
Authorized
Blynk is Online! << This comes from my app.

— Runs fine for hours to days then

Disconnect blynk << My app does not get an interrupt. see code below.
REARMING DISCONNECT
SSL authorization...
Connected << My app does not get an interrupt on this connection
--- Runs fine for hours to days Repeating the disconnect - reconnect now and then
--- Never offline for more than a few minutes and typically only seconds
--- I have a socket connection to another Raspberry pi that logs data
--- Seems normal with infrequent interruptions
Disconnect blynk
REARMING DISCONNECT
SSL authorization...
Connected

— Runs fine for hours to days then

Disconnect blynk << My app does not get an interrupt. see code below.
REARMING DISCONNECT
Connecting to: blynk-cloud.com 8441
SSL authorization...
Connected << My app does not get an interrupt on this connection 
Disconnect blynk
REARMING DISCONNECT
SSL authorization...
Connected

— This cycle repeats more than 150 times. While this is occurring,
— my logging server repeatedly pings this RPi and time.com
— without interruption or significant delay.

error @ line 221 ECONNRESET
events.js:142
      throw err;
 ..... crash! The trace listing only lists Blynk's blynk.js and blynk-node.js modules

My connect / disconnect event code:

The connect code fires and works at initial connect only.

blynk.on('connect', function() {
	BLYNK_CONNECTED = true;
    	console.log('Blynk is Online!');
    	ledColor(BlynkLED, GRN);
    	init();
});

The disconnect code works properly when I explicitly close the connection

blynk.on('disconnect', function() {
    DATE_TIME = DateTime.create();
    EventTimeDisplay.write(DATE_TIME.format('H:M:S') + ' ' + CURRENT_TEMP + 'F');
    ActivityDisplay.write('Blynk Disconnected');
    ledColor(BlynkLED, RED);
})

Yeah, I have the same problem.
Probably there is a bug in the JS library, which is unmaintained.
If you switch from using SSL to pure TCP, the issue is still there but the app won’t crash. It will remain continuously in a connect-disconnect loop.

I still suspect NodeJS needs better code management then we might be used to with C++? I am unconvinced that the Library itself is at fault, as it is otherwise very stable until I do some strange coding routine that causes issues.

While Googling this error (I often wonder why more don’t do this simple step :thinking: ) I came across this document…

Not clear what it is exactly about? but I found the “error?” message buried in what looks like the routine that runs it when some other error in one’s code trips a condition?

https://npmdoc.github.io/node-npmdoc-blynk-library/build/apidoc.html#apidoc.element.blynk-library.Blynk.prototype.disconnect

The rest of the document looks like some potentially helpful stuff for potentially understanding this library

I may have missed it if someone resolved the issue. However I thought I’d pass this along. I implemented a “giant hand fix” by monitoring the running NodeJS module, Sensing that it had crashed or was in one of its interminable “trying to restart” loops and killed it if it was. I then waited five minutes and attempted a restart of the module. This most often worked in less than three tries. Typically looping or crashing occurred every 24 to 40 hours.

Recently, I needed to make a change to the module so while I was at it, I deleted all reference to Web and espruino from blynk.js and for not good reason deleted those from node_modules… My program just past 700 hours continuous operation without a loop or crash. No idea if I fixed anything but… Simplest Does Prove Best sometimes.

Note: Raspberry pi Model B