electron-connect icon indicating copy to clipboard operation
electron-connect copied to clipboard

restart() closes the window, but never opens a new one

Open jayarjo opened this issue 5 years ago • 1 comments

For me restart() closes the window but never opens a new one. From what I see in the source, in order to respawn the process, logic should enter the if (!this.numClients) {... conditional, but it never does, since numClients is decremented only after the client closes websocket connection and for this to happen, probably process should be killed first.

ProcessManager.prototype.restart = function (args, cb) {
  // ...

  if (typeof cb === 'function') {
    this.restartCallback = cb;
  }

  this.electronState = 'restarting';
  if (this.electronProc) {
    this.info('restarting electron process: ' + this.electronProc.pid);
    if (!this.numClients) {
      this.killProcess(function() {
        this.info('respawning electron process..');
        this.spawn(args, this.opt.spawnOpt);
        this.setStateAndInvokeCallback('restarted', this.restartCallback);
      }.bind(this));
    } else {
      this.killProcess(function() {
        if (this.restartCallback) {
          this.restartCallback(this.electronState);
        }
      }.bind(this));
    }
  }
};

jayarjo avatar Mar 07 '19 19:03 jayarjo

electron-connect server starts many electron processes (much more than one or two), I suppose that's just how underlying Chromium works?

screenshot from 2019-03-08 10-24-13

But the real problem it seems is that after electron-connect does killProcess not all of those processes disappear. At least two are left:

screenshot from 2019-03-08 10-25-16

If I kill them off manually then websocket gets finally closed and restart logic kicks in, respawning electron window.

Shouldn't killProcess shutdown the whole tree of processes?

jayarjo avatar Mar 08 '19 06:03 jayarjo