Skip to content
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

fix: crash problem with message_port close event #41201

Merged
merged 1 commit into from Feb 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion patches/chromium/.patches
Expand Up @@ -47,7 +47,6 @@ feat_add_support_for_overriding_the_base_spellchecker_download_url.patch
feat_enable_offscreen_rendering_with_viz_compositor.patch
gpu_notify_when_dxdiag_request_fails.patch
feat_allow_embedders_to_add_observers_on_created_hunspell.patch
feat_add_onclose_to_messageport.patch
allow_in-process_windows_to_have_different_web_prefs.patch
refactor_expose_cursor_changes_to_the_webcontentsobserver.patch
crash_allow_setting_more_options.patch
Expand Down
31 changes: 0 additions & 31 deletions patches/chromium/feat_add_onclose_to_messageport.patch

This file was deleted.

53 changes: 53 additions & 0 deletions spec/api-ipc-spec.ts
Expand Up @@ -345,6 +345,59 @@ describe('ipc module', () => {
}})()`);
});
});

describe('when context destroyed', () => {
it('does not crash', async () => {
let count = 0;
const server = http.createServer((req, res) => {
switch (req.url) {
case '/index.html':
res.setHeader('content-type', 'text/html');
res.statusCode = 200;
count = count + 1;
res.end(`
<title>Hello${count}</title>
<script>
var sharedWorker = new SharedWorker('worker.js');
sharedWorker.port.addEventListener('close', function(event) {
console.log('close event', event.data);
});
</script>`);

break;
case '/worker.js':
res.setHeader('content-type', 'application/javascript; charset=UTF-8');
res.statusCode = 200;
res.end(`
self.addEventListener('connect', function(event) {
var port = event.ports[0];
port.addEventListener('message', function(event) {
console.log('Message from main:', event.data);
port.postMessage('Hello from SharedWorker!');
});
});`);
break;
default:
throw new Error(`unsupported endpoint: ${req.url}`);
}
});
const { port } = await listen(server);
defer(() => {
server.close();
});
const w = new BrowserWindow({ show: false });
await w.loadURL(`http://localhost:${port}/index.html`);
expect(w.webContents.getTitle()).to.equal('Hello1');
// Before the fix, it would crash if reloaded, but now it doesn't
await w.loadURL(`http://localhost:${port}/index.html`);
expect(w.webContents.getTitle()).to.equal('Hello2');
// const crashEvent = emittedOnce(w.webContents, 'render-process-gone');
// await crashEvent;
});
});
});

describe('MessageChannelMain', () => {
Expand Down