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

MathJax hangs Chrome #548

Closed
ricardobeat opened this issue Aug 19, 2013 · 104 comments
Closed

MathJax hangs Chrome #548

ricardobeat opened this issue Aug 19, 2013 · 104 comments

Comments

@ricardobeat
Copy link

Hi,

It's about the third time this week I've got my browser completely frozen from opening a blog post. I noticed they all hang with the little "Typesetting Math: x%" at the bottom left, and found this library.

I'm running Chrome 28.0.1500.71 on OSX Mountain Lion. Here is one such post: http://www.leancrew.com/all-this/2013/08/hyperloop/

@pkra
Copy link
Contributor

pkra commented Aug 20, 2013

Since we haven't heard any similar reports, I'm guessing this isn't a bug directly. Have you tried clearing your browser cache? Perhaps one of the MathJax files is corrupted.

@ricardobeat
Copy link
Author

Checked other versions, 27 and 29 do not exhibit the issue. Source corruption would be unlikely to cause a lock-up instead of an error, if it could happen at all. Since it pegs the CPU at 100%, I was thinking an infinite loop/recursion somewhere in the layout code. Will investigate further.

@pkra
Copy link
Contributor

pkra commented Aug 20, 2013

Thanks for the update. It could be that one of MathJax (many) components has been corrupted but I'm guessing you've actually tried clearing the cache.

Thanks for investigating further. I can't reproduce this on Chrome 28 under Ubuntu btw.

@dpvc
Copy link
Member

dpvc commented Aug 21, 2013

I am not able to reproduce this with Chrome 28.0.1500.95 on Max OS X 10.7.4.

Note, however, that the page you cite has a lot of other stuff to download in the sidebar, and that will compete with MathJax's loading of the components that it needs. Since the site does not use MathJax's combined configuration files, each component has to be downloaded separately (this is the least efficient type of configuration), and I see a fairly long delay before MathJax actually can begin its typesetting as it loads the components that it needs in order to do that. When the sidebar finishes loading, MathJax is able to get its code more quickly.

So perhaps you are just not being patient enough?

@ricardobeat
Copy link
Author

@dpvc as mentioned above, CPU usage for the process hikes up to 100%, and MathJax is already loaded since it hangs with the 'Typesetting Math' status display in the bottom left. I'm seeing this even in MathJax's own website.

@dpvc
Copy link
Member

dpvc commented Aug 21, 2013

MathJax is not all one file. It always has to load at least one other file, and many times it may load a dozen or so. The site that you indicate has a configuration that requires it to load more than that. So the fact that the you have a typesetting message does not mean that MathJax has finished loading what it needs.

You might also try disabling the STIX fonts so that MathJax will use its web-based fonts and see if that makes a difference.

The fact that we have not had any other reports of this issue suggests that this has something specific to do with your installation. The fact that you don't see the problem in Chrome 27 or 29, and that I don't see it for Chrome 28, suggest that it is not a loop in the layout code (as the same code runs for all those versions), though certainly it doesn't rule that out. Just because the MathJax message area is showing doesn't mean that it is MathJax code that is taking up the CPU (MathJax gives up the processor in order to display the message, so it could be something else running at that time).

Have you tried disabling any plugins that you have in Chrome? Perhaps one of those is interacting badly with MathJax.

@ricardobeat
Copy link
Author

@dpvc I don't own that blog. As I just said, even MathJax's own website hangs, so it's definitely not something pertaining to this specific blog's configuration. In fact, as far as I could find, any website using MathJax hangs when using this version. I'll probably only have time to look further into this early next week.

@dpvc
Copy link
Member

dpvc commented Aug 21, 2013

Yes, I heard you when you said the MathJax site also gave the same problem. I was explaining why having the typesetting messages does not mean MathJax was (completely) loaded, as your message seemed to suggest.

The fact that this happens for you an any site with MathJax further suggests that is is a problem somewhere with your installation (meaning your computer/browser/OS, not the site you are looking at). That is, I suspect problem is specific to something in the setup on your computer. That is why I suggested turning of plugins in your browser, for example. And why I suggested turning off the STIX fonts (use FontBook for that). Perhaps you can try those things early next week.

@dpvc dpvc closed this as completed Dec 17, 2013
@jakevdp
Copy link

jakevdp commented Mar 24, 2014

I just saw the same thing. Both in the IPython notebook, and on blogs which use MathJax. The "Typesetting Math: 100%" appears in the bottom left corner, and then the page freezes. There's nothing strange in the JS console (I need to open it beforehand, because once the page freezes it's not possible.

I've been using mathjax/ipython notebook on this computer for over a year with no problem. I didn't install anything new, or change my browser, or anything, but mathjax started freezing today. Very strange...

@jakevdp
Copy link

jakevdp commented Mar 24, 2014

Looks like some sort of infinite loop: looking at the chrome task manager, the memory footprint of any window with mathjax counts up at ~0.5MB/sec, with the CPU consistently at 100%.

I'm on Chrome 33.0.1750.152

(Edit: BTW, the easiest way to see this is to just go to mathjax.org)

@jakevdp
Copy link

jakevdp commented Mar 24, 2014

Here's a screen shot, for what it's worth:
screen shot 2014-03-24 at 3 51 13 pm

@jakevdp
Copy link

jakevdp commented Mar 24, 2014

Cleared the cache, and the problem went away. Very strange...

@pkra
Copy link
Contributor

pkra commented Mar 25, 2014

Thanks for reporting this in detail. When cleaning the cache resolves things, it's usually a sign that one of MathJax's files was corrupted or that the cache contained a mix of different MathJax versions. It's rare, but it happens. Glad to see you could resolve it.

@soumith
Copy link

soumith commented Aug 24, 2014

same thing has been happening to me on Chrome 36.0.1985.143 (latest as of now), and clearing the cache didn't help in any way (neither did running in an incognito window with all extensions disabled).

@pkra
Copy link
Contributor

pkra commented Aug 25, 2014

@soumith could you provide more information such as specific pages (unless it's global) and your OS. FWIW, I don't have any issues with that Chrome version on ubuntu 14.04.

@dpvc
Copy link
Member

dpvc commented Aug 25, 2014

I have no problem with Chrome 36.0.1985.143 on Mac OS X 10.7.5 on the MathJax home page.

@adriweb
Copy link

adriweb commented Sep 19, 2014

I have this issue on Chrome 38.0.2125.66 beta running on Yosemite 10.10 DP8.
Clearing the cache didn't help.
(Edit : on any website having MathJax, including the home page)
(Edit2 : a reboot made the problem disappear, but that's not really satisfying... something corrupted beyond the browser cache but still related to MathJax ?)

@pkra
Copy link
Contributor

pkra commented Sep 20, 2014

@adriweb sorry to hear that. That's two betas combined so I'm wondering if it was just a fluke (I find Chrome 38 on linux to be a particularly unstable beta).

Can you let us know if it happens again? First thing to check would be the developer console to see if there are any errors or warnings. Thanks!

@adriweb
Copy link

adriweb commented Sep 20, 2014

Will do, but when I checked, there was nothing in the console...

@pkra
Copy link
Contributor

pkra commented Sep 22, 2014

@adriweb hm. well, if you encounter it again, try MathJax.Message.Log() in the console to get MathJax's internal log.

@adriweb
Copy link

adriweb commented Sep 22, 2014

Well, I'd like to, but considering the whole tab gets frozen, the console can't get access to the page, so it's impossible to get anything...
I suppose having a bunch of console.log at key places within MathJax's script could help locating the issue since we'd have a "live log" on where (until) it crashes...

@pkra
Copy link
Contributor

pkra commented Sep 22, 2014

Ah, ok -- that bad...

If it's not site specific, then load http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html and see how far you get. If it is site specific, then you could grab the scripts from that example (it's in this repo under /test) and add them to your page.

@adriweb
Copy link

adriweb commented Sep 22, 2014

Well, here's bad news : it's totally random :(
Sometimes it actually reaches the end of the script ("MathJax is done"), sometimes it crashes at the beginning or right in the middle of everything...
In any case, though, the tab ends up frozen. Right now, it's eating 128 MB of RAM (and keeps increasing), with a 100% CPU (of quad-core, so not "all" the CPU, but still). Then Chrome asks if it should kill the process because it's stuck (it doesn't always detect it, though, in which case I have to kill it manually)

@h2kfl
Copy link

h2kfl commented Oct 21, 2014

exactly same problem at Chrome 38.02125.104m on Windows 7 64bit. I experienced a tab loading MathJax occupied over 200MB.

@adriweb
Copy link

adriweb commented Oct 21, 2014

Note : the problem disappeared (on its own ?) for me some time ago, and since then I have not had any issue...

@pkra pkra changed the title MathJAX hangs Chrome/OSX MathJax hangs Chrome/OSX Oct 21, 2014
@pkra
Copy link
Contributor

pkra commented Oct 21, 2014

@h2kfl do you have a link to a page that exhibits this? We've seen pretty random memory issues with Chrome in the past which came down to specific content+configurations and never enough data to file a bug report.

@h2kfl
Copy link

h2kfl commented Oct 21, 2014

@pkra you can check this site:
https://sagenb.h2kfl.com/home/pub/0/ - my sage notebook site. I updated MathJax to v2.4 latest.
and this problem is at http://www.mathjax.org/ also. I'm running Windows 7 64bit and Chrome 38.0.2125.104 m (recently updated and facing this problem). There's no problem with Chrome 38.0.2125 and OS X 10.8.

default

@pkra
Copy link
Contributor

pkra commented Oct 21, 2014

@h2kfl is that the new 64bit Chrome? (FWIW I'm not seeing any problems on Linux either.) I'll try to reproduce this tomorrow.

@pkra
Copy link
Contributor

pkra commented Jan 7, 2015

@dpvc ok. I've updated title and labels; reopening.

@pkra pkra reopened this Jan 7, 2015
@dpvc
Copy link
Member

dpvc commented Jan 8, 2015

Here are a couple of other things to try:

  • Do you get the same results if you use in-line math via \(...\) rather than \[...\]?

  • If you turn off font matching, does that change anything? Use

    MathJax.Hub.Config({
      "HTML-CSS": {matchFontHeight: false}
    });
    

    to turn that off.

@ManuelLlorens
Copy link

No difference for me in any of the two cases.

@ManuelLlorens
Copy link

I have notice this: sometimes, when the browser freezes, the MathJax output message is: Loading web-font TeX/Math/Italic instead of Typesetting Math x%.

@nkurz
Copy link

nkurz commented Jan 9, 2015

I'm currently experiencing the same symptoms with 39.0.2171.95 (64-bit) on OSX 10.9.5. Manuel's SVG example works fine, but the HTML-CSS version hangs. http://mathjax.org/ loads correctly, but http://cdn.mathjax.org/mathjax/latest/test/sample-signals.html hangs.

I haven't tried restarting or clearing cache yet. If there is any information or logs that I can help provide, I'd be glad to try help. I'm Linux low-level literate, but not familiar with the tools available on OSX. I can install software as necessary.

I'll hold off on trying to fix the problem for a day or two in case there's something useful I can do.

@ManuelLlorens
Copy link

I suppose someone has already done this, but just to confirm I have tested this with MathJax 2.5 beta and it also freezes.

@h2kfl
Copy link

h2kfl commented Jan 22, 2015

@nkurz could you update Chrome to 40.0.2214.91 m (latest). It works for me. I've exprienced hang up with Chrome for Windows 7 64bit. But it seems fine now.

@nkurz
Copy link

nkurz commented Jan 22, 2015

I'm currently running 39.0.2171.99 (64-bit) on OSX, and all appears
to be working correctly. The bug persisted until I restarted Chrome.
Attempts to clear caches and other in-browser actions had no effect.
I'm not sure if a restart alone would have been enough to solve it,
as it updated automatically at the same time.

@dpvc
Copy link
Member

dpvc commented Jan 22, 2015

In Chrome reseting the cache is not enough to clear MathJax (I'm not sure why). You do have to restart the browser as well.

@ManuelLlorens
Copy link

In Android 5.0.2; Nexus 7 Build/LRX22G, Chrome 40.0.2214.89 still hungs.

@ofb
Copy link

ofb commented Jan 26, 2015

I'm running android 5.0.2 and chrome 40.0.2214.89 as well on a nexus 10. The nexus 10 has been hanging on mathjax for what is probably over a year; I just haven't seen much discussion about it online before now, so I didn't pursue it. The maddening thing for me is that sometimes I have opened pages (usually on mathoverflow.net) that freeze 4 times in a row in different places, and then on the fifth time make it through and render, but then the tab freezes completely and you can't click links or even move the page up and down. It'd be great if this ever gets fixed.

@pkra pkra added the Abandoned label Apr 20, 2016
@pkra
Copy link
Contributor

pkra commented Apr 20, 2016

=> marked as abandoned.

Not looking forward to this Frankenbug resurfacing.

@pkra pkra closed this as completed Jul 11, 2016
@adamwulf
Copy link

adamwulf commented Feb 21, 2018

I was able to create a test case that reproduces the issue 100% of the time with the current master branch (commit 2965eab).

The test case can be found here: www.wikipediacorpus.com/Chapter1.html - Opening that URL will cause MathJax to hang in an infinite loop.

The issue seems to occur when the browser fails to load a supporting resource file for some reason. In the example URL, i forced MathJax/jax/output/HTML-CSS/autoload/mtable.js to 404 by renaming it to mtable2.js on the server. I'm purposefully causing the break here, but there's tons of reasons why a browser might fail to load a resource, which explains why it's been so hard to reproduce.

When that file fails to load, the processOutput function circles in an infinite loop, continually trying to restart. I've added a console.log() to that method, which prints out the state.i value, and you can see in the JavaScript console that the value never increments above 7. The line that is throwing the restart error is line 2334:

        result = MathJax.OutputJax[jax.outputJax].Process(script,state);

As a workaround, the following seems to fix the issue:

         try{
                result = MathJax.OutputJax[jax.outputJax].Process(script,state);
         }catch(e){
            if(state.i == state.lastErr){
                state.i++;
                console.log("state.i: " + state.i);
            }else{
                state.lastErr = state.i;
                console.log("other: " + state.i);
            }
            throw e;
         }

Otherwise, that line throws a restart Error, having never incremented state.i, and the whole process repeats itself.

I ran into this issue while working on MacDown, a native markdown client for Mac, which uses MathJax in its preview window (issue 807). On every edit, the preview window is reloaded, which occasionally causes scripts to fail to load, which sometimes causes this infinite recursion, hanging the app.

@vyznev
Copy link

vyznev commented Feb 21, 2018

@adamwulf I suspect that may be a different issue than what's discussed above (not that I'm even 100% sure that the issues discussed above are really just one issue). Still, it does look like this may be a genuine MathJax bug, in any case.

My Chromium 64.0.3282.167 doesn't hang on your test page, but it does peg one CPU core at 100% for a few seconds before giving up with the following error on the console:

MathJax.js?config=TeX-AMS-MML_HTMLorMML:2378
Uncaught RangeError: Maximum call stack size exceeded
    at Object.processError (MathJax.js?config=TeX-AMS-MML_HTMLorMML:2378)
    at Object.processOutput (MathJax.js?config=TeX-AMS-MML_HTMLorMML:2356)
    at Function.execute (MathJax.js?config=TeX-AMS-MML_HTMLorMML:243)
    at cb (MathJax.js?config=TeX-AMS-MML_HTMLorMML:225)
    at Function.AFTER [as After] (MathJax.js?config=TeX-AMS-MML_HTMLorMML:374)
    at Object.processError (MathJax.js?config=TeX-AMS-MML_HTMLorMML:2381)
    at Object.processOutput (MathJax.js?config=TeX-AMS-MML_HTMLorMML:2356)
    at Function.execute (MathJax.js?config=TeX-AMS-MML_HTMLorMML:243)
    at cb (MathJax.js?config=TeX-AMS-MML_HTMLorMML:225)
    at Function.AFTER [as After] (MathJax.js?config=TeX-AMS-MML_HTMLorMML:374)

(That's the partial stack trace shown in Chromium's console by default. Clicking the triangle to expand the full stack trace just shows the same five function loop repeated over and over and over.)

@adamwulf
Copy link

I went ahead and opened a separate issue #1936 in case the cause is different than this older issue.

@dpvc
Copy link
Member

dpvc commented Feb 22, 2018

You are right, it is a different issue. Thanks for opening the other one.

@xiuliren
Copy link

this issue have a temporal fix:
jupyter/jupyter#227

Using this command:
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace Notebook.ipynb
(just replace Notebook.ipynb with your own file name)

@ricardobeat
Copy link
Author

Isn't it crazy that the bug still hasn't been found 6 years later? 🤕

On the bright side I haven't seen this issue in the past half decade. Looking at the code mentioned in #548 (comment):

MathJax/unpacked/MathJax.js

Lines 2293 to 2315 in 419b0a6

prepareOutput: function (state,method) {
while (state.j < state.jaxIDs.length) {
var id = state.jaxIDs[state.j], JAX = MathJax.OutputJax[id];
if (JAX[method]) {
try {
var result = JAX[method](state);
if (typeof result === 'function') {
if (result.called) continue; // go back and try again
this.RestartAfter(result);
}
} catch (err) {
if (!err.restart) {
MathJax.Message.Set(["PrepError","Error preparing %1 output (%2)",id,method],null,600);
MathJax.Hub.lastPrepError = err;
state.j++;
}
return MathJax.Callback.After(["prepareOutput",this,state,method],err.restart);
}
}
state.j++;
}
return null;
},
, I think it's clear the error is simply that state.j is not incremented at all in the catch block when err.restart == true, leading to infinite retries of the failed op. According to @dpvc's explanation:

when MathJax needs to load a file, it starts the download, then throws a "restart" error (that includes a pointer to the callback that will be called when the asynchronous action is complete). The try/catch that you have removed traps that error, and when the callback is completed, it restarts the processing of that equation again

And then the use of timers somewhere in the callback system would prevent Chrome from triggering either a stack overflow, or the "script taking too long" message. This could be mitigated by keeping a counter and giving up after X retries.

@dpvc
Copy link
Member

dpvc commented Jun 9, 2019

I think it's clear the error is simply that state.j is not incremented at all in the catch block when err.restart == true, leading to infinite retries of the failed op.

While that was a suggestion at one point for what the problem was, it turns out not to be the case, as further investigation showed that MathJax completed its operations before the hang occurred. (See this comment.) This shows that it is not an infinite look inside MathJax (the routine you quote above is not looping), and the issue was taken to be in Chrome itself somewhere. Since it has not been reported again since 2015 (the 2018 case was a different issue, with was dealt with in a separate issue tracker), I suspect that updates in Chrome have resolved the problem, whatever it was.

As I mention above, MathJax doesn't produce a reset twice for the same condition (that would be an error), so while the code you quote could loop, in practice that doesn't occur, and didn't occur for the problem being investigated in this issue tracker.

@oooredooo-bit
Copy link

oooredooo-bit commented Aug 26, 2022

I would like to raise the same issue I encounter right now:

Uncaught RangeError: Maximum call stack size exceeded
at Object.processError (:19:41875)
at Object.processOutput (:19:41327)
at Function.execute (:19:3242)
at cb (:19:2819)
at Function.AFTER [as After] (:19:6707)
at Object.processError (:19:41960)
at Object.processOutput (:19:41327)
at Function.execute (:19:3242)
at cb (:19:2819)
at Function.AFTER [as After] (:19:6707)

Can anyone provide an update to this? Thank you very much.

I'm still using MathJax@2.7.9.

@dpvc
Copy link
Member

dpvc commented Aug 31, 2022

@redooo666, can you provide a link to a page where this is occurring for you? Does it always occur, or is it intermittent? What browser and os are you using, and what versions?

After the error occurs, if you enter MathJax.Message.Log() in the browser console, are there any messages about filing to load a file?

@crackwitz
Copy link

if anyone needs an example of mathjax locking up the browser: https://docs.opencv.org/4.x/d2/de8/group__core__array.html

@pkra
Copy link
Contributor

pkra commented Sep 8, 2022

if anyone needs an example of mathjax locking up the browser: https://docs.opencv.org/4.x/d2/de8/group__core__array.html

That page renders fine for me (Chrome 105.0.5195.102), even throttling down CPU 6x, switching MathJax renderers etc. (FWIW, that page uses 2.7.0 which is 6 years old now.)

@dpvc
Copy link
Member

dpvc commented Sep 8, 2022

It also works fine for me in every situation I tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests