How do I stop infinite loop / expensive call?

I’m now implementing some expensive grid operations and sometimes I execute something too expensive, or infinite loop and then I can’t stop it.

Even if the code runs in a extension page (tab), closing the tab doesn’t stop the execution.
And the addon can’t even be reloaded from the about:debugging#/runtime/this-firefox page.

Is there any other way to kill the process?

Please show us the snippet or give us more technical details. I had something similiar in the past.

After further investigation and testing, I’ve realized that my grid crawler is synchronous, so the event loop never got a chance to break to “kill itself” once the tab got closed.

So, it was basically something like this:

while(true) { console.log('noooooo') }

I would recommend NOT executing this in your normal Firefox as it will freeze almost whole browser with no way to stop it.

If you use recursion, the code will usually quickly fail with stack overflow, but if you don’t overflow the stack, it will just kill the browser and you need to restart it.

Eventually I’ve fixed it using a timeout that will stop the crawler (it checks current time).

So… The question remains, how do I stop the infinite script?
I tried to use the task manager to kill the extension process, which helped, however, I could no longer inspect the background script, so not a great workaround.

Can you uninstall the addon from about:debugging#/runtime/this-firefox ?

Have you tried using a separate instance of Worker ? This will definitely prevent UI freezing and give you more control over execution. However, it’s better to think about the exact conditions under which execution must be stopped. I’m not sure you can do that based on resource consumption information, if that’s what you want to do.

The issue is not that the code was slow to execute. And I’m aware of the need of having a fail-safe (timeout or some counter) when dealing with possible infinite loops (like when using the MutationObserver).

The issue I’m trying to solve is - once I make a mistake, during development, how do I fix it without the need of restarting browser?

I’m developing using web-ext and usually my addon is in some specific testing state with a specific data loaded, so getting it back to this state and re-openning all the windows, tabs, consoles, resizing them and placing them around my monitors, takes quite some time and effort :slight_smile:.
Usually I close my Firefox only once a month when I need to reboot PC due to updates :slight_smile:.

@hans_squared, I did tried to uninstall it, but it didn’t helped and my whole PC almost crashed since it caused a huge (20GB+) memory leak! :smiley:

Try it yourself, it’s fun! :smiley:

  1. open your addon folder
  2. run web-ext run
  3. open addon page and run: while(true) {console.log('noooooo')}
  4. now try to recover :slight_smile: