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

Hangs (spinning beachball) and sucks memory #807

Closed
theodore-norvell opened this issue May 13, 2017 · 54 comments
Closed

Hangs (spinning beachball) and sucks memory #807

theodore-norvell opened this issue May 13, 2017 · 54 comments

Comments

@theodore-norvell
Copy link

theodore-norvell commented May 13, 2017

I'm using 0.7 (861) on a document with a lot of mathjax code in it. Quite often, MacDown will hang (spinning beachball) and the memory usage of the OS kernel_task goes way up; e.g. from less than 2 GB to over 5 GB. MacDown's memory also goes up. If I don't force quit macdown quickly, available physical memory hits 0 and the whole computer is almost bricked. Once I force quit MacDown, things go back to normal.

I think the problem is correlated with editing the MathJax code.

I had the same problem on the previous version (not sure the number) that I used. Although it seems more frequent since upgrading to 0.7 (861).

Great program when it works, by the way.

@chipbrock
Copy link

This is exactly what I see, but I don't correlate it with MathJax. I think there's some buffering problem in the editor since when I'm doing something like deleting or typing fast is when it will happen. It's sometimes just unusable.

@FranklinYu
Copy link
Member

Sometimes when I force quit an application, macOS gives a pop up saying something like "MacDown quit unexpectedly" or "MacDown is not responding". Did you guys meet such pop-up dialog window?

@chipbrock
Copy link

No. I have to go to the Activity Monitor in order to see that it's "not responding"...and it's then probably taking more than 100% of CPU. I force quit it from there, not from the Apple menu. Glad you're looking at it, as it's the single thing that keeps me from relying on MacDown...it's so useful that I keep going back but then frustrating because of the hanging...that I then leave for a while!

Is there any way after the fact to capture any data that would help?

@theodore-norvell
Copy link
Author

theodore-norvell commented May 13, 2017

I got this nice report from the Activity Monitor. Note the virtual memory size.
screen shot 2017-05-13 at 17 42 43
screen shot 2017-05-13 at 17 42 15

@chipbrock
Copy link

Actually, I'm not doing anything...I went away and came back and looked at the same report that you are and see

screenshot_863

@chipbrock
Copy link

chipbrock commented May 13, 2017

Just hung on my again. Here's a sample immediately after:

Sampling process 23354 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling MacDown (pid 23354) every 1 millisecond
Process:         MacDown [23354]
Path:            /Applications/MacDown.app/Contents/MacOS/MacDown
Load Address:    0x1092eb000
Identifier:      com.uranusjr.macdown
Version:         0.7 (861)
Code Type:       X86-64
Parent Process:  ??? [1]

Date/Time:       2017-05-13 17:38:47.139 -0400
Launch Time:     2017-05-13 15:41:18.612 -0400
OS Version:      Mac OS X 10.12.3 (16D32)
Report Version:  7
Analysis Tool:   /usr/bin/sample
----

Call graph:
    2260 Thread_3880202   DispatchQueue_1: com.apple.main-thread  (serial)
    + 548 ???  (in <unknown binary>)  [0x5d3f44227192]
    + ! 548 ???  (in <unknown binary>)  [0x5d3f44259bf3]
    + !   548 ???  (in <unknown binary>)  [0x5d3f43d35288]
    + !     548 ???  (in <unknown binary>)  [0x5d3f43c41aed]
    + !       548 ???  (in <unknown binary>)  [0x5d3f43c7069c]
    + !         548 ???  (in <unknown binary>)  [0x5d3f44227192]
    + !           548 ???  (in <unknown binary>)  [0x5d3f44259bf3]
    + !             548 ???  (in <unknown binary>)  [0x5d3f43d35288]
    + !               548 ???  (in <unknown binary>)  [0x5d3f43c41aed]
    + !                 548 ???  (in <unknown binary>)  [0x5d3f43c7069c]
    + !                   548 ???  (in <unknown binary>)  [0x5d3f44227192]
    + !                     548 ???  (in <unknown binary>)  [0x5d3f44259bf3]
    + !                       548 ???  (in <unknown binary>)  [0x5d3f43d35288]
    + !                         548 ???  (in <unknown binary>)  [0x5d3f43c41aed]
    + !                           548 ???  (in <unknown binary>)  [0x5d3f43c7069c]
    + !                             548 ???  (in <unknown binary>)  [0x5d3f44227192]
    + !                               548 ???  (in <unknown binary>)  [0x5d3f44259bf3]
    + !                                 548 ???  (in <unknown binary>)  [0x5d3f43d35288]
    + !                                   548 ???  (in <unknown binary>)  [0x5d3f43c41aed]
    + !                                     548 ???  (in <unknown binary>)  [0x5d3f43c7069c]
    + !                                       548 ???  (in <unknown binary>)  [0x5d3f44227192]
    + !                                         548 ???  (in <unknown binary>)  [0x5d3f44259bf3]
    + !                                           548 ???  (in <unknown binary>)  [0x5d3f43d35288]
    + !                                             548 ???  (in <unknown binary>)  [0x5d3f43c41aed]
    + !                                               548 ???  (in <unknown binary>)  [0x5d3f43c7069c]
    + !                                                 548 ???  (in <unknown binary>)  [0x5d3f44227192]
    + !                                                   548 ???  (in <unknown binary>)  [0x5d3f44259bf3]

I cut out about 600 lines of this... the attachment is the whole dump
Untitled 11.txt

@FranklinYu
Copy link
Member

@chipbrock Thank you very much for the stack dump. That definitely seems wrong.

@FranklinYu FranklinYu added the bug label May 13, 2017
@uranusjr
Copy link
Member

Looks like an infinite loop (or recursion). Will need to investigate to know where exactly this happens though.

@FranklinYu
Copy link
Member

@chipbrock I don't think so; you are probably just being lucky. Will still need to investigate about this issue.

@chipbrock
Copy link

chipbrock commented May 15, 2017 via email

@hirmes
Copy link

hirmes commented May 16, 2017

I'm having this same issue with 0.7.1: When editing a file that contains Mathjax, eventually I'll get a beachball/freeze. It seems to be fine on relaunch as long as I don't make any edits. Note that the edits don't have to be in the Mathjax portion of the markdown to cause the freeze. Stack dump excerpt:

Thread 0x65038e         DispatchQueue 1         10 samples (1-10)       priority 46 (base 46)   cpu time 0.882s
 <thread QoS user interactive (requested user interactive), process unclamped, process received importance donation from WindowServer [207], IO policy important>
 1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360835745) [0x472ad45552a1] 1
   1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244358268018) [0x472ad42e2472] 1
     1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360940005) [0x472ad456e9e5] 1
       1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244361096230) [0x472ad4594c26] 1
         1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360968934) [0x472ad4575ae6] 1
           1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360835745) [0x472ad45552a1] 1
             1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244358268018) [0x472ad42e2472] 1
               1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360940005) [0x472ad456e9e5] 1
                 1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244361096230) [0x472ad4594c26] 1
                   1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360968934) [0x472ad4575ae6] 1
                     1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360835745) [0x472ad45552a1] 1
                       1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244358268018) [0x472ad42e2472] 1
                         1  ??? (<469ED9FF-BEE6-392D-806F-217B35DDAE68> + 78244360940005) [0x472ad456e9e5] 1

@chipbrock
Copy link

any progress? I'm willing go try a beta of an update. this is a great app and will change my workflow considerably so I'm eager for it to succeed!

@FranklinYu
Copy link
Member

The call graph mentioned JavaScriptCore many times, so I suspect that there's something wrong with some JavaScript code included. @uranusjr Do you think updating Prism would help? I'm thinking about PrismJS/prism#1001.

@FranklinYu
Copy link
Member

Anyone provide some sample Markdown file that ever crashed MacDown, for us to test?

@chipbrock
Copy link

chipbrock commented Jun 10, 2017

hi

I've attached the (draft!!) file that I've been working on. Since I first posted, it's about twice as long as it was and does have one javascript reliance (a tool to convert dimensions) that it didn't have when I first started having trouble. It lives inside of a Jekyll environment.
I have no history with Macdown beyond this document.

Git won't let me upload an mmd document directly. It's zipped

I hope you can find the issue! I know that Macdown would make my life easier. I've been using Atom since this became a problem. I've also looked at Lightpaper, but it's dreadfully slow to render mathematics and the active preview does not sync properly.

thanks
Ray

motionAZ4.md.zip

@danielparton
Copy link

danielparton commented Jun 21, 2017

I've had similar problems editing files with multiple latex equations.
Sample markdown file is here.

This was memory usage, which was still climbing when I killed the process:
screen shot 2017-06-21 at 1 58 08 pm

@FranklinYu
Copy link
Member

I have opened the Markdown files (both from @danielparton and @chipbrock) and kept it in background for an hour. Nothing has happened.

  1. Is there anything you were doing when MacDown eats your memory?
  2. When you were editing this file, how often does this (high memory consumption) happen? Always?
  3. It's probably not related, but which version of macOS are you using?

@danielparton
Copy link

I had a number of apps open - a lot of Chrome tabs. But still had 6GB RAM free without MacDown running.

I tried closing MacDown and re-opening the file a few times. Each time, I'd be able to edit a few characters, then the same thing would happen - spinning beach ball, and the memory starts spiking.

It has happened to me a few times before with other files. Pretty sure it has always occurred in files with a fairly large number of mathjax equations (say around 10 or more).

OS X version: 10.12.5

Thanks for looking into this! MacDown is awesome. Let me know if there's anything else I can do to help debug.

@uranusjr
Copy link
Member

Since this occurs only recently, I can think of a couple of possibilities:

  • I recently upgraded to Sierra (yes I am very late to the party, I know). Maybe the toolchain changes somehow and doesn’t like my JavaScript anymore. Or maybe this is related to that HTTPS thing that bugged us for quite a while before.
  • We switched from Mathjax.org to CDNJS for MathJax hosting because the former shut down last month. Maybe the connection is not as good and somehow jams the CPU (because if the synchronous nature of <script> download).

My gut instinct points the second one. And if I’m correct (no guarantee), the solution would be to host MathJax locally, or do some manual caching as mentioned in #789 (comment).

@FranklinYu
Copy link
Member

Wait, how would memory be eaten by jamming the CPU?

@chipbrock
Copy link

chipbrock commented Jun 22, 2017 via email

@danielparton
Copy link

The previous times this issue occurred (with different markdown files from the one I posted), the beachball did go away after around 5-20 seconds.
With the file I posted here, the beachball was spinning for a long time while the memory usage started spiking, so every time I killed the process.

I've disabled automatic rendering, so hopefully that will work as a stopgap.

@theodore-norvell
Copy link
Author

About OS versions: This started happening shortly after I upgraded to Sierra (10.12.5, I think) from 10.11.??. But it also started happening shortly after I upgraded MacDown to 0.7. So it's hard to correlate the problem with either upgrade.

@chipbrock
Copy link

I saw this before I upgraded my OS and before upgrading the application on three computers.

Any progress?

thanks

@Muxelmann
Copy link

Hi, I am also experiencing this "beachball of death" problem. My MacDown version is using nearly 18GB of RAM? Has there been any update?

bildschirmfoto 2017-06-28 um 12 32 31

@FranklinYu
Copy link
Member

@Muxelmann The “virtual memory” is not the amount of memory actually used by an application. We should focus on the “physical memory” here. Nevertheless, 6.51 GB of physical memory is clearly unexpected; thanks for the report.

@goodman-capu
Copy link

Anyone has got any ideas? This bug is kind of driving me crazy...

@infusion
Copy link

I encounter the same problem every now and then and it's really annoying. Any news on that?

@goodman-capu
Copy link

goodman-capu commented Dec 8, 2017

This is really a SERIOUS bug that happens every time and someone please do something...

The file is a sample file from macOS Activity Monitor when this happens.
MacDown Sample.txt

@goodman-capu
Copy link

goodman-capu commented Dec 9, 2017

And here is a sample file. Password is "fixit". Just do some quick typing and deletions and then it will freeze.

crash_file.zip

@theodore-norvell
Copy link
Author

For what it's worth, I was able to reproduce the problem with Goodman's file.

@koeppeda
Copy link

Anyone know if we have a solve for this issue yet? I'm trying to write up a short document but it freezes after just a couple lines of typing.

@FranklinYu
Copy link
Member

FranklinYu commented Dec 18, 2017

@goodman-capu's Markdown file consumes about 100 MB memory on my Mac, although it takes the preview about three seconds to update. The UI doesn't freeze.

There is a lot of mathematics formula in the file (reminds my good old days in college, writing my assignment with LaTeX), so this file confirms again that MathJax plays a role here.

@goodman-capu
Copy link

@FranklinYu Just do some quick typing and deleting anywhere, and the UI will surely freeze.

@MiroFurtado
Copy link

MiroFurtado commented Jan 31, 2018

Any update on this issue? I'm also editing somewhat Latex heavy documents and the freezing is constant and making the app close to unusable.

Mine ultimately recovers, but is pretty frustrating

@infusion
Copy link

infusion commented Feb 1, 2018

This problem is really a show stopper for MacDown. I started with disabling and re-enabling tex support constantly while writing but have now switched to a normal code editor with pandoc and a web-browser...

@marc-medley
Copy link

marc-medley commented Feb 1, 2018

@infusion @goodman-capu @MiroFurtado In my use case, if Update preview automatically as you type is disabled, then crashes do not occur while editing and a periodic cmd-R Markdown Render (when I'm not otherwise editing) is reliable.

Disabling Update preview automatically as you type is my current editing workaround for large markdown files.

Is disabling Update preview automatically as you type an effective workaround for the frozen app issue for anyone else?

@infusion
Copy link

infusion commented Feb 1, 2018

Oh, that's a good hint. Thanks, I'll give that a try.

@adamwulf
Copy link
Contributor

I just submitted #930 which is helping considerably with this issue for me. It doesn't 100% solve beachballing, but when it happens its much more rare and much shorter. I'd be interested to know if this fixes for others as well.

@adamwulf
Copy link
Contributor

So it seemed better, but was still beachballing occasionally for me. I decided to dig into MathJax and try and figure out what was going wrong.

You can see the cause + solution of the MathJax issue in my comment on their repo's issue.

As a workaround, my latest commit bundles a fixed version of MathJax.js, and will load all other resources from the CDN as it already does.

@infusion
Copy link

infusion commented Feb 21, 2018

Adam, you are the best! Thanks for tracing the root cause of the problem. It looks you solved the problem in a way that a lot of people benefit from it. Thanks!!

Could you open a PR for Mathjax? I don't know how long it will take they see activity on this closed issue.

@daviewales
Copy link

daviewales commented Feb 27, 2018

I don't know if this is still relevant, but I have found this issue occurs in the following situation:

Internet disconnected.
Markdown document open, with some LaTeX in it.
Add the following:

\begin{align}

\end{align}

Then, between the two align tags, start typing x_ (with the intention of typing x_1.

Macdown will freeze. Memory usage will surge.

I wonder if it has anything to do with the fact that the underscore is both Markdown and LaTeX syntax.

@adamwulf
Copy link
Contributor

@daviewales where you able to reproduce this on the current master branch? I tried and am no longer able to get MacDown to freeze, even following these steps.

@goodman-capu
Copy link

I now believe it has something to do with poor network. Any updates on this?

@landalex
Copy link

landalex commented Apr 5, 2018

With @adamwulf's fix in MacDown #932 (plus his root cause fix being merged mathjax/MathJax#1936 in MathJax for version 2.7.4), can this be closed? What's the process to make a new MacDown release that includes this fix?

@working-name
Copy link

@landalex is that fix actually considered a fix? It's more of a forced timeout in terms of not letting MacDown hang too long on refreshing the preview pane.

The issue is still there however. I have manually applied the patch and compiled MacDown to test it and confirm.

@uranusjr
Copy link
Member

uranusjr commented Apr 7, 2018

@working-name #932 actually does more than just adding the timeout—it vendors the MathJax library directly into MacDown, so parsing does not require Internet connection anymore (displaying still does because you need some web fonts to show the result). I don’t think it’d stuck on poor Internet anymore.

Also I published a prerelease version containing the fix yesterday; you can test that directly.

@working-name
Copy link

Ooops, I apologize, you're correct @uranusjr. I was unable to get it to beach-ball again on #932 or the pre-release.

Thank you!

@uranusjr
Copy link
Member

uranusjr commented Apr 7, 2018

🎉

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