Skip to content

[Bug]: loadURL after did-start-loading crashes electron #19847

Closed

Description

@t57ser

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:
    • 5.0.10 , 6 ,7
  • Operating System:
    • Windows 10
  • Last Known Working Electron version: ?

Expected Behavior

No crash

Actual Behavior

In electron 5 it crashes with the following code: 2147483651
in electron 6 and 7 it just seems to hang but is basically dead

To Reproduce

const { app, BrowserWindow, BrowserView } = require("electron");

const init = () => {
	let browserWindow = new BrowserWindow({
		show: true,
	});
	browserWindow.loadURL("https://www.google.com");

	let browserWindow2 = new BrowserWindow({
		show: true,
	});

	browserWindow2.webContents.once("did-start-loading", () => {
		browserWindow2.loadURL("https://www.google.com");
	});
	browserWindow2.loadURL("https://www.test.com");

};

app.on("ready", () => {
	init();
});

Additional Information

Activity

  1. vladimiry commented on Oct 24, 2019

    @vladimiry

    Not sure if this is related. If I'm not wrong since electron v5 an error will be thrown if new url triggered for loading before the previous one got loaded. Here is the respective code

    return rejectAndCleanup(-3, 'ERR_ABORTED', url)
    CC @MarshallOfSound

  2. MarshallOfSound commented on Oct 24, 2019

    @MarshallOfSound
    Member

    This kinda makes sense, Chromium does not expect a new navigation to clear out pending navigations while a navigationentry is dispatching an event. Wrapping this in a setTimeout(() => loadUrl(), 0) should stop it crashing.

    On Electron's side we should probably detect this and wait a tick or something 🤷‍♂

  3. sdetweil commented on Nov 29, 2019

    @sdetweil

    Actually, this is a bigger problem.. I have two additions to two SPA Mirror projects.. MagicMirror and smart-mirror. both extensions load images, one on the main html page (thru DHTML or Angular expressions), and one on a separate thread, above the main page, using Javascript (not in the dom) both are driven off timer tick, and loadUrl in a setTimeout timer handler

    IF one extension attempts to loadUrl ITS content and the other is waiting (loadUrl started, and before webContents.on('did-finish-load'), ) then the renderer will crash, or hang. the addition that does the windows ABOVE the index.html page can be driving multiple windows concurrently (images tied to calendar entries). I spent a few months finding and fixing my concurrent calls into electron, but now have added this other thing that displays background images on the page.

    in my calendar based code I have a serialization flag, that prevents me having two loadUrls active at the same time.

    I started my calendar app in 2016 and I am seeing the same issues now on 6.0.12.. neither mirror app runs on electron above 6.1.x

    if the electron code is not re-entrant, then it either needs a queue of loadUrl requests, or an exception if already busy.

    I notice that the window that dies is the main html page, not the javascript created windows over the html page

  4. sdetweil commented on Dec 1, 2019

    @sdetweil

    i have had to resort to on('crashed') to workaround the problem, restarting the app.. I'd make an override class if I could. as one loadUrl is coming from angular when an img element is surfaced.

  5. zbot473 commented on Mar 31, 2020

    @zbot473

    Getting this on Win10 on v8.2.0

  6. electron-triage commented on Mar 8, 2021

    @electron-triage

    The Electron version reported on this issue is no longer supported. See our supported versions documentation.

    If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know.

    Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated.

  7. 14 remaining items

  8. nornagon commented on Oct 31, 2022

    @nornagon
    Contributor

    It looks like the underlying functions that LoadURL calls are explicitly non-reentrant—see https://bugs.chromium.org/p/chromium/issues/detail?id=347742 and https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/navigation_controller_impl.cc;l=2611-2614;drc=2c82547348818858d793ae04f3ad950e3f2567b4—and the did-start-loading event is emitted during the non-reentrant "critical section".

    So I see three possible paths for addressing this crash:

    1. Delay the did-start-loading event until after the critical section completes. Though I'm not sure what method/event to hook in Chromium that would give us "after the critical section", or even if there is one. Possibly did-start-navigation?
    2. Detect when loadURL is called during the critical section, and queue the call until the critical section ends. Again, not quite sure how to detect the end of the critical section, but maybe for this one we could just wait until the next tick.
    3. Have loadURL throw if it's called during the critical section, instead of crashing the whole app. Document this in the docs for did-start-loading and anywhere else that's "inside the critical section".

    I'm not sure what all the possible events are that can happen "inside the critical section" where calling loadURL will crash, but I've noticed at least did-start-loading and frame-created can be emitted during that time.

  9. github-actions commented on Jan 30, 2023

    @github-actions
    Contributor

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  10. pushkin- commented on Jan 30, 2023

    @pushkin-

    repros in v22

  11. changed the title [-]loadURL after did-start-loading crashes electron[/-] [+][Bug]: loadURL after did-start-loading crashes electron[/+] on Apr 2, 2023
  12. github-actions commented on Jul 2, 2023

    @github-actions
    Contributor

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  13. pushkin- commented on Jul 3, 2023

    @pushkin-

    bump

  14. self-assigned this
    on Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions