Issue 1:
Preflight Checklist

I have read the Contributing Guidelines for this project.

I agree to follow the Code of Conduct that this project adheres to.

I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

Electron Version:

9.0.4

Operating System:

Windows 10

Last Known Working Electron version:

Not sure

Expected Behavior

Node.js APIs to work normally like when app.allowRendererProcessReuse is set to false

Actual Behavior

Node.js APIs callbacks never trigger when app.allowRendererProcessReuse is set to true

To Reproduce

$ git clone https://github.com/aabuhijleh/allowRendererProcessReuse-reload-issue.git
$ npm install
$ npm start

Reload the page

fs.readdir's callback for example in the preload script never triggers

document.getElementById("readdirBtn").addEventListener("click", async () => {
await ipcRenderer.invoke("createWindow");
console.log("before readdir");
fs.readdir(path.dirname(process.execPath), async (err, items) => {
console.log("readdir", err, items); // never reached after reload <------
await ipcRenderer.invoke("closeWindow");
});
});

Screen Recording

Issue 2:
Preflight Checklist

I have read the Contributing Guidelines for this project.

I agree to follow the Code of Conduct that this project adheres to.

I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

Electron Version:

8.0.0

Operating System:

Windows 10 (1809)

Last Known Working Electron version:

Unknown

When setting app.allowRendererProcessReuse = true and after reloading the renderer (Ctrl+R in developer console), Node fs APIs would randomly stop working. Specifically, the callbacks are never called, or if you're using fs.promises, the promises are never resolved.

An interesting observation is: when you reload again, for a brief moment before the page is refreshed, the previous fs calls are magically unblocked. This can be observed by console.log lines suddenly printing the moment you hit Ctrl+R which disappears quickly as the whole page reloads.

Possibly related: #19554 This issue sounds like the opposite of what's happening here.

Also note: issue does not present itself when app.allowRendererProcessReuse = false

Expected Behavior

From the repro steps, expecting to see local files printed in the console:

...
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

Actual Behavior

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.

To Reproduce

Clone https://github.com/electron/electron-quick-start

rendereer.js

(async () => {
const fs = require('fs').promises;

for (let i = 0; i < 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');
})();

main.js

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', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

Screenshots

First boot:

On reload:

Additional Information