title: Electron event emitter error while app.quit with closing all open renderer processes
body: <p>I have one main window listing all available servers with a status button which has the id of the server. An info window is opened after pressing the related status button - passing the id to the copy of info window, making the status button disabled. If the info window is closed, the info window passes back the id to the main window so it makes the status button enabled again. To do that, I'm using <code>main.js</code> as a proxy, listening to the renderer processes and exchange information between main window and info window.</p>
  
  <p>The thing that I'm trying to do is to list servers. If they are online, get some information from multiple servers at once on different renderer processes (instance of info window).</p>
  
  <p>The problem is I want all info windows to be closed if the main window is closed.</p>
  
  <pre><code>// App ready
  app.on('ready', ()=&gt;{
      mainWindow = new BrowserWindow({x : 0, y : 0 , width : 500, height: 600});
  
      mainWindow.loadURL(url.format({
          pathname : path.join(__dirname, 'windows', 'mainWindow.html'),
          protocol : 'file',
          slashes : true
      }));
  
      // Close the app if main window closed
      mainWindow.on('close', (e) =&gt; {
          let openedOnes = BrowserWindow.getAllWindows();
          openedOnes.forEach(wind =&gt; {
              if(wind.hasOwnProperty('custom')){
                  wind.close();
              };
          });
  
          app.quit();
      });
  });
  </code></pre>
  
  <p>While creating info window, I add a custom field to the <code>BrowserWindow</code> object:</p>
  
  <pre><code>BrowserWindow {
    _events:
     { blur: [Function],
       focus: [Function],
       show: [Function: visibilityChanged],
       hide: [Function: visibilityChanged],
       minimize: [Function: visibilityChanged],
       maximize: [Function: visibilityChanged],
       restore: [Function: visibilityChanged],
       close: [Function: callIntoRenderer] },
    _eventsCount: 8,
    devToolsWebContents: [Getter],
    custom: { server_id: '3' } }
  </code></pre>
  
  <p>So with the help of the custom field, I can get all opened server info instances.</p>
  
  <p>But when I click close, the following part is failing at <code>main.js</code>;</p>
  
  <pre><code>ipcMain.on('window_closed', (e, item)=&gt;{
      mainWindow.webContents.send('button_enable', item);
  });
  </code></pre>
  
  <p>It raises the following error.</p>
  
  <p><a href="https://i.stack.imgur.com/1aLeG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1aLeG.jpg" alt="enter image description here"></a></p>
  
  <p><code>main.js:53</code> is the line <code>ipcMain.on('window_closed'...</code>. By the way, if I omit this line everything works perfectly.</p>