Quramy / electron-connect

Livereload tool for Electron
https://www.npmjs.com/package/electron-connect
340 stars 54 forks source link

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

Open jayarjo opened 5 years ago

jayarjo commented 5 years ago

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 commented 5 years ago

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?