<h3 dir="auto">Preflight Checklist</h3>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the <a href="https://github.com/electron/electron/blob/master/CONTRIBUTING.md">Contributing Guidelines</a> for this project.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow the <a href="https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md">Code of Conduct</a> that this project adheres to.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the issue tracker for an issue that matches the one I want to file, without success.</li>
</ul>
<h3 dir="auto">Issue Details</h3>
<ul dir="auto">
<li><strong>Electron Version:</strong>
<ul dir="auto">
<li>
 9.0.4
</li>
</ul>
</li>
<li><strong>Operating System:</strong>
<ul dir="auto">
<li>
 Windows 10
</li>
</ul>
</li>
<li><strong>Last Known Working Electron version:</strong>
<ul dir="auto">
<li>
 Not sure
</li>
</ul>
</li>
</ul>
<h3 dir="auto">Expected Behavior</h3>

<p dir="auto">Node.js APIs to work normally like when <code class="notranslate">app.allowRendererProcessReuse</code> is set to <code class="notranslate">false</code></p>
<h3 dir="auto">Actual Behavior</h3>

<p dir="auto">Node.js APIs callbacks never trigger when <code class="notranslate">app.allowRendererProcessReuse</code> is set to <code class="notranslate">true</code></p>
<h3 dir="auto">To Reproduce</h3>



<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ git clone https://github.com/aabuhijleh/allowRendererProcessReuse-reload-issue.git
$ npm install
$ npm start"><pre class="notranslate">$ git clone https://github.com/aabuhijleh/allowRendererProcessReuse-reload-issue.git
$ npm install
$ npm start</pre></div>
<ul dir="auto">
<li>Reload the page</li>
<li><code class="notranslate">fs.readdir</code>'s callback for example in the preload script never triggers</li>
</ul>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  document.getElementById(&quot;readdirBtn&quot;).addEventListener(&quot;click&quot;, async () =&gt; {
    await ipcRenderer.invoke(&quot;createWindow&quot;);
    console.log(&quot;before readdir&quot;);
    fs.readdir(path.dirname(process.execPath), async (err, items) =&gt; {
      console.log(&quot;readdir&quot;, err, items); // never reached after reload &lt;------
      await ipcRenderer.invoke(&quot;closeWindow&quot;);
    });
  });"><pre class="notranslate">  <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">getElementById</span><span class="pl-kos">(</span><span class="pl-s">"readdirBtn"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">"click"</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">await</span> <span class="pl-s1">ipcRenderer</span><span class="pl-kos">.</span><span class="pl-en">invoke</span><span class="pl-kos">(</span><span class="pl-s">"createWindow"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"before readdir"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">fs</span><span class="pl-kos">.</span><span class="pl-en">readdir</span><span class="pl-kos">(</span><span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">dirname</span><span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">execPath</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">,</span> <span class="pl-s1">items</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"readdir"</span><span class="pl-kos">,</span> <span class="pl-s1">err</span><span class="pl-kos">,</span> <span class="pl-s1">items</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// never reached after reload &lt;------</span>
      <span class="pl-k">await</span> <span class="pl-s1">ipcRenderer</span><span class="pl-kos">.</span><span class="pl-en">invoke</span><span class="pl-kos">(</span><span class="pl-s">"closeWindow"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Screen Recording</h3>

<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/42934634/84900914-6e09ec00-b0b3-11ea-8c19-b9c9d8de44fb.gif"><img src="https://user-images.githubusercontent.com/42934634/84900914-6e09ec00-b0b3-11ea-8c19-b9c9d8de44fb.gif" alt="reproduce issue" data-animated-image="" style="max-width: 100%;"></a></p>
<h3 dir="auto">Preflight Checklist</h3>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the <a href="https://github.com/electron/electron/blob/master/CONTRIBUTING.md">Contributing Guidelines</a> for this project.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow the <a href="https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md">Code of Conduct</a> that this project adheres to.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the issue tracker for an issue that matches the one I want to file, without success.</li>
</ul>
<h3 dir="auto">Issue Details</h3>
<ul dir="auto">
<li><strong>Electron Version:</strong>
<ul dir="auto">
<li>8.0.0</li>
</ul>
</li>
<li><strong>Operating System:</strong>
<ul dir="auto">
<li>Windows 10 (1809)</li>
</ul>
</li>
<li><strong>Last Known Working Electron version:</strong>
<ul dir="auto">
<li>
Unknown
</li>
</ul>
</li>
</ul>
<p dir="auto">When setting <code class="notranslate">app.allowRendererProcessReuse = true</code> and after reloading the renderer (<code class="notranslate">Ctrl+R</code> in developer console), Node <code class="notranslate">fs</code> APIs would randomly stop working. Specifically, the callbacks are never called, or if you're using <code class="notranslate">fs.promises</code>, the promises are never resolved.</p>
<p dir="auto">An interesting observation is: when you reload again, for a brief moment before the page is refreshed, the previous <code class="notranslate">fs</code> calls are magically unblocked. This can be observed by <code class="notranslate">console.log</code> lines suddenly printing the moment you hit <code class="notranslate">Ctrl+R</code> which disappears quickly as the whole page reloads.</p>
<p dir="auto">Possibly related: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="475351669" data-permission-text="Title is private" data-url="https://github.com/electron/electron/issues/19554" data-hovercard-type="issue" data-hovercard-url="/electron/electron/issues/19554/hovercard" href="https://github.com/electron/electron/issues/19554">#19554</a> This issue sounds like the opposite of what's happening here.</p>
<p dir="auto">Also note: issue does not present itself when <code class="notranslate">app.allowRendererProcessReuse = false</code></p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">From the repro steps, expecting to see local files printed in the console:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="...
renderer.js:8 Reading file main.js
renderer.js:8 Reading file package-lock.json
renderer.js:8 Reading file package.json
renderer.js:8 Reading file preload.js
renderer.js:8 Reading file README.md
renderer.js:8 Reading file renderer.js
renderer.js:14 done"><pre class="notranslate"><code class="notranslate">...
renderer.js:8 Reading file main.js
renderer.js:8 Reading file package-lock.json
renderer.js:8 Reading file package.json
renderer.js:8 Reading file preload.js
renderer.js:8 Reading file README.md
renderer.js:8 Reading file renderer.js
renderer.js:14 done
</code></pre></div>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">List is printed the first time the app loads. Hit Ctrl+R and observe only a few lines printed, or none at all. Hit Ctrl+R again and observe more lines printed for a split second before renderer reloads.</p>
<h3 dir="auto">To Reproduce</h3>
<p dir="auto">Clone <a href="https://github.com/electron/electron-quick-start">https://github.com/electron/electron-quick-start</a></p>
<p dir="auto">rendereer.js</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(async () =&gt; {
	const fs = require('fs').promises;

	for (let i = 0; i &lt; 10; i++) {
		let list = await fs.readdir('.', {withFileTypes: true});
		for (let file of list) {
			if (file.isFile()) {
				console.log('Reading file', file.name);
				await fs.readFile(file.name, 'utf-8');
			}
		}
	}

	console.log('done');
})();"><pre class="notranslate"><code class="notranslate">(async () =&gt; {
	const fs = require('fs').promises;

	for (let i = 0; i &lt; 10; i++) {
		let list = await fs.readdir('.', {withFileTypes: true});
		for (let file of list) {
			if (file.isFile()) {
				console.log('Reading file', file.name);
				await fs.readFile(file.name, 'utf-8');
			}
		}
	}

	console.log('done');
})();
</code></pre></div>
<p dir="auto">main.js</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const {app, BrowserWindow} = require('electron');

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  });

  win.loadFile('index.html');
  win.webContents.openDevTools();
}

app.whenReady().then(createWindow);

app.allowRendererProcessReuse = true;
app.on('window-all-closed', () =&gt; {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () =&gt; {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});"><pre class="notranslate"><code class="notranslate">const {app, BrowserWindow} = require('electron');

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  });

  win.loadFile('index.html');
  win.webContents.openDevTools();
}

app.whenReady().then(createWindow);

app.allowRendererProcessReuse = true;
app.on('window-all-closed', () =&gt; {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () =&gt; {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});
</code></pre></div>
<h3 dir="auto">Screenshots</h3>
<p dir="auto">First boot:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/609710/74136094-80cb5c00-4bbb-11ea-92fd-c49b87b3a9f3.png"><img src="https://user-images.githubusercontent.com/609710/74136094-80cb5c00-4bbb-11ea-92fd-c49b87b3a9f3.png" alt="image" style="max-width: 100%;"></a><br>
On reload:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/609710/74136317-cd169c00-4bbb-11ea-8e81-caf0e967bbd9.png"><img src="https://user-images.githubusercontent.com/609710/74136317-cd169c00-4bbb-11ea-8e81-caf0e967bbd9.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional Information</h3>