mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Remove the race condition between new process creation and context release (#12342)
* Remove the race condition between new process creation and old process releasing remote context Previously there was a race condition where the getId() method would return the new context ID even though the release was for the old context. This changes it to send the "initial" context ID with the release message to ensure there is no race. * fetch context ID from remote in sandbox mode
This commit is contained in:
@@ -268,7 +268,7 @@ ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', (event, id) => {
|
||||
|
||||
process.on('exit', () => {
|
||||
const command = 'ELECTRON_BROWSER_CONTEXT_RELEASE'
|
||||
ipcRenderer.sendSync(command)
|
||||
ipcRenderer.sendSync(command, initialContext)
|
||||
})
|
||||
|
||||
exports.require = (module) => {
|
||||
@@ -295,6 +295,15 @@ exports.getCurrentWebContents = () => {
|
||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS'))
|
||||
}
|
||||
|
||||
const CONTEXT_ARG = '--context-id='
|
||||
let initialContext = process.argv.find(arg => arg.startsWith(CONTEXT_ARG))
|
||||
if (initialContext) {
|
||||
initialContext = parseInt(initialContext.substr(CONTEXT_ARG.length), 10)
|
||||
} else {
|
||||
// In sandbox we need to pull this from remote
|
||||
initialContext = exports.getCurrentWebContents().getId()
|
||||
}
|
||||
|
||||
// Get a global object in browser.
|
||||
exports.getGlobal = (name) => {
|
||||
const command = 'ELECTRON_BROWSER_GLOBAL'
|
||||
|
||||
Reference in New Issue
Block a user