getEventStream dies after few days

I’m trying to hold a persistent connection to the particle cloud so that I can receive updates to my backend based on publishes from the P1s I have in the field. Everything works great, but after a few days the connection is lost and I no longer receive any signals despite the server functioning normal. I tried to implement this examples, but it is still failing

I am wondering if something is wrong with the code below, or if I’m missing another piece. Thanks!

var mysql = require('mysql');
var cluster = require('cluster');
var os = require('os');
var bunyan = require('bunyan');
var spark = require('spark');
var async = require('async');
var net = require('net');
var config = require('./api/config.js');

var log = bunyan.createLogger({ name: 'services' });

var pool = mysql.createPoolCluster();

if (cluster.isMaster) {

  var numWorkers = os.cpus().length;'Master cluster setting up ' + numWorkers + ' workers...');
  for (var i = 0; i < numWorkers; i++) {
    var worker = cluster.fork();

  spark.login(config.particleLogin, function(err, body) {
    if (err) {
    }{ spark: body });
  var openStream = function() {
    var req = spark.getEventStream(false, 'mine', function(data) {

    req.on('end', function() {
      log.warn('Particle server ended!  re-opening in 3 seconds...');
      setTimeout(openStream, 3 * 1000);

  spark.on('login', function() {

  cluster.on('online', function(worker) {'Worker ' + + ' is online');

  cluster.on('exit', function(worker, code, signal) {'Worker ' + + ' died with code: ' + code + ', and signal: ' + signal);'Starting a new worker');
} else {

  process.on('message', function(data) {
    if (!data) {




Are you able to see if the the openStream function is called each time a message is published to see what’s not triggering/running?

Not seeing anything really, ideally the openStream function only gets called with the particle login. It definitely does when I restart the server, but somehow it’s not being called when there is a reset from particle’s end.

This should kick in when that scenario happens… Let’s see what the other Javascript gurus have to say :slight_smile: