Skip to content

Freezing on iOS Net 9 Maui ? #880

Open

Description

@EricLVertiGIS

Hi, we have a .NET Maui application. Since upgrading to .NET 9, our app freezes on iOS when our custom Markdown view reappears (ie. filtered then unfiltered inside a CollectionView). At first I thought it might be a Maui issue, but after investigation, the only line that causes this behavior is :
Markdig.Markdown.Parse(Markdown)

Our issue behaves quite similar to #585. It works fine in Debug Mode, but on Release Mode (iOS only), the freeze happens. I saw that a fix was released in https://github.com/xoofx/markdig/pull/600/files, but updating to the newest version didn't resolve the issue.

.NET 9 Maui added changes to trimming code, so that could be a factor. The Markdown view is garbaged collected then recreated each time it disappears / reappears, but Parse is static so that shouldn't be a problem.

Could the team please look into this ? Thank you

Activity

  1. EricLVertiGIS commented on Jun 23, 2025

    @EricLVertiGIS
    Author

    Actually it seems our issue might be with the way newline is encoded. @xoofx What is Markdig's preferred / supported way to do line breaks ? Does it support double space, '', what about '\n' ?

  2. MihaZupan commented on Jun 23, 2025

    @MihaZupan
    Collaborator

    Markdig treats "\r", "\n", or "\r\n" pretty much the same. Hard line breaks do support double spaces before a new line.

    I don't see how that's related to "freezing" in release?

  3. EricLVertiGIS commented on Jun 23, 2025

    @EricLVertiGIS
    Author

    @MihaZupan Our Markdown code calls Markdig.Markdown.Parse(Markdown) and then creates the views to display. If I comment out the view creation, just the parse alone causes the freeze on iOS release.

    The markdown being passed in was:
    "# Basic info\n**Trap Type:** Hawaii \\\n**Last Inspected:** Hawaii \\\n**Last Relocated:** Hawaii \\\n\n\n## Age groups \\\nUnder 5: 78163 \\\n_AGE_5_17:_ 217604 \\\n_AGE_18_21:_ 65456 \\\n*AGE_22_29:* 133437 \\\n*AGE_30_39:* 183094 \\\n**AGE_40_49:** 185646 \\\n**AGE_50_64:** 187536 \\\n*AGE_65_UP:* 160601"

    This freezes. I then tried hard coding some simpler markdown and it worked fine. So something about this string is causing issues.

    Sorry to bring up such a niche & complicated issue 😓

  4. EricLVertiGIS commented on Jun 23, 2025

    @EricLVertiGIS
    Author

    We have CollectionView where each item is one MarkdownView. Each MarkdownView calls parse to render its markdown. It seems the parsing becomes more and more stable the shorter the markdown string is. I couldn't find a particular sequence that was problematic.

    I'm unfamiliar with how CollectionView is implemented on iOS, but I imagine its rendering the views in parallel. Maybe when many complicated parses are happening in parallel, it ends up in a deadlock some how ?

  5. MihaZupan commented on Jun 23, 2025

    @MihaZupan
    Collaborator

    I doubt anything in Markdig on its own could lead to a deadlock.

    If it's never happening in Debug but reliably on Release that sounds more like a possible issue in the underlying runtime, e.g. maybe a different manifestation of #873.

    Does the issue reproduce on a nightly build of .NET 10 main and MAUI?
    https://github.com/dotnet/dotnet/blob/main/docs/builds-table.md
    https://github.com/dotnet/maui/wiki/Nightly-Builds

  6. EricLVertiGIS commented on Jun 24, 2025

    @EricLVertiGIS
    Author

    @MihaZupan Thank you, #873 does share similarities with to our issue. I saw that there is a PR for it dotnet/runtime#116069 but couldn't find it in the dotnet/runtime release notes. Maybe 9.0.7 will releases the fixes.

    Like #873, once we hit some sort of threshold, Parse freezes. If I make the markdown string shorter, it takes more calls of Parse to get the freeze. If I make the markdown string longer, it takes less calls of Parse to reach the freeze. Unlike #873, our threshold is based on the cumulative length of the markdown strings rather than the the number of calls. Also different from #873 is our app freezes instead of crashes (on iOS I think exceptions would just crash).

    I'll retry once 9.0.7 releases and see if that fixes thing. I'll update this if I find anything new in the meantime.

  7. EricLVertiGIS commented on Jul 22, 2025

    @EricLVertiGIS
    Author

    Hi @MihaZupan, I retested this with Maui 9.0.90 and .NET SDK 9.0.7, and Markdig 0.41.3, the issue still reproduces. It seems like it just crashes/freezes once Mardown.Parse is called many times. I created a simple repro. It's the base .NET Maui template. In the MainPage constructor, I added:

    var data = "# Basic info\n**Trap Type:** Hawaii \\\n**Last Inspected:** Hawaii \\\n**Last Relocated:** Hawaii \\\n\n\n## Age groups \\\nUnder 5: 78163 \\\n_AGE_5_17:_ 217604 \\\n_AGE_18_21:_ 65456 \\\n*AGE_22_29:* 133437 \\\n*AGE_30_39:* 183094 \\\n**AGE_40_49:** 185646 \\\n**AGE_50_64:** 187536 \\\n*AGE_65_UP:* 160601";
    
    for (int i = 0; i < 200; i++)
    {
    
        var _ = Markdig.Markdown.Parse(data);
    }
    

    On iPhone 11, iOS 18.5. It runs fine in debug mode. But on release mode (or no debugger attached), the app will crash.

    Attached Repro Demo: MarkdigiOSFreeze.zip

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions