Danny
Danny

Reputation: 588

Why does my whole Ubuntu system freeze on buggy javascript code in Firefox?

I have been experiencing a weird problem in Ubuntu 18.04 and 19.04 (fresh install too), Firefox 64 - 66.0.3 (fresh). I am writing some JavaScript code and checking it in my browser. Sometimes I make mistakes like this:

for(var i = 0; i < 100;){
   something_else();
}

that is, infinite loops. Last time it was a new Regex(...).test() with a wrong regex which obviously caused an infinite loop... I should be careful, that's right, but the problem IS:

Does not only my Firefox say something like 'This page is not okay, close it?' but the system itself does not say something like 'This Firefox is not okay, kill it?'

I get a full system freeze without any chance of recovery. All I can do is Alt+SysRq+REIUSB. So debugging my code becomes a problem à la 1978 with multiple reboots, where failing to save the code means losing it. To me it sounds crazy.

I've reinstalled Ubuntu a few times, switched between 18.04 and 19.04, updated the software, all to no avail. The CPU seems to be cool enough, there is no screen blinking, there are no other obvious hardware issues.

UPD: I also ran sudo stress --cpu 4 to check what happens at 100% load. The system does not freeze.

So, the question. What am I doing wrong? Why doesn't my OS or Firefox intercept those freezes?

Upvotes: 3

Views: 1495

Answers (1)

Ry-
Ry-

Reputation: 224905

Like you expect, Firefox should prompt you to stop a script when it’s an infinite loop keeping time away from the UI, and it should be possible to kill the Firefox process either way. If the script also uses an increasing amount of memory, though, that can be much more of a problem. In my experience, Linux doesn’t deal with OOM conditions very well, and it especially didn’t in older kernel versions – ones Ubuntu might still be on, for example.

A helpful tool is SysRq+F (make sure it’s enabled by checking sysctl kernel.sysrq; a value of 1 or with bit 6 set – x & 64 ≠ 0 – means it is), which runs the OOM killer manually.

Upvotes: 3

Related Questions