8000 fix: libuv hang on Windows by codebytere · Pull Request #28175 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: libuv hang on Windows #28175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions shell/common/node_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,13 @@ void NodeBindings::LoadEnvironment(node::Environment* env) {
void NodeBindings::PrepareMessageLoop() {
#if !defined(OS_WIN)
int handle = uv_backend_fd(uv_loop_);
#else
HANDLE handle = uv_loop_->iocp;
#endif

// If the backend fd hasn't changed, don't proceed.
if (handle == handle_)
return;

handle_ = handle;
#endif

// Add dummy handle for libuv, otherwise libuv would quit when there is
// nothing to do.
Expand Down
4 changes: 1 addition & 3 deletions shell/common/node_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ class NodeBindings {
// Isolate data used in creating the environment
node::IsolateData* isolate_data_ = nullptr;

#if defined(OS_WIN)
HANDLE handle_;
#else
#if !defined(OS_WIN)
int handle_ = -1;
#endif

Expand Down
13 changes: 13 additions & 0 deletions spec-main/fixtures/apps/libuv-hang/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<script src="./renderer.js"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions spec-main/fixtures/apps/libuv-hang/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');

async function createWindow () {
const mainWindow = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});

await mainWindow.loadFile('index.html');
}

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

let count = 0;
ipcMain.handle('reload-successful', () => {
if (count === 2) {
app.quit();
} else {
count++;
return count;
}
});

app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});
16 changes: 16 additions & 0 deletions spec-main/fixtures/apps/libuv-hang/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('api', {
ipcRenderer,
run: async () => {
const { promises: fs } = require('fs');
for (let i = 0; i < 10; i++) {
const list = await fs.readdir('.', { withFileTypes: true });
for (const file of list) {
if (file.isFile()) {
await fs.readFile(file.name, 'utf-8');
}
}
}
}
});
8 changes: 8 additions & 0 deletions spec-main/fixtures/apps/libuv-hang/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const count = localStorage.getItem('count');

const { run, ipcRenderer } = window.api;

run().then(async () => {
const count = await ipcRenderer.invoke('reload-successful');
if (count < 3) location.reload();
}).catch(console.log);
11 changes: 11 additions & 0 deletions spec-main/node-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ifdescribe, ifit } from './spec-helpers';
import { webContents, WebContents } from 'electron/main';

const features = process._linkedBinding('electron_common_features');
const mainFixturesPath = path.resolve(__dirname, 'fixtures');

describe('node feature', () => {
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
Expand All @@ -22,6 +23,16 @@ describe('node feature', () => {
});
});

it('does not hang when using the fs module in the renderer process', async () => {
const appPath = path.join(mainFixturesPath, 'apps', 'libuv-hang', 'main.js');
const appProcess = childProcess.spawn(process.execPath, [appPath], {
cwd: path.join(mainFixturesPath, 'apps', 'libuv-hang'),
stdio: 'inherit'
});
const [code] = await emittedOnce(appProcess, 'close');
expect(code).to.equal(0);
});

describe('contexts', () => {
describe('setTimeout called under Chromium event loop in browser process', () => {
it('Can be scheduled in time', (done) => {
Expand Down
0