Skip to content

Renderer Node fs API stops working on page reload when allowRendererProcessReuse is true #22119

@lishid

Description

@lishid

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:
image
On reload:
image

Additional Information

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions