Skip to content

Main thread waits on the Live Markdown runtime with no limit, so a parser that touches the UI runtime can hang the app #824

Open

Description

@mountiny

Problem

The main thread can wait on the Live Markdown worklet runtime with no time limit. If a parser worklet waits on Reanimated's UI runtime at the same moment, for example by reading a SharedValue, the two threads wait on each other and the app hangs.

Expensify App hit this as an iOS App Hang (Sentry APP-M0W) and as Android ANRs (APP-KA6, APP-KY2, APP-KH2, APP-NC2, APP-M9K). TaduJR confirmed the lock owners with lldb:

  1. The main thread runs a Reanimated layout animation and holds the UI runtime. It mounts a MarkdownTextInput, and updateProps → applyNewStyles parses the text and waits for the Live Markdown runtime.
  2. The JS thread runs the parser on the Live Markdown runtime. The parser reads a SharedValue, which in Reanimated 4 is a synchronous call into the UI runtime, so it waits for the main thread.

App fixed its parsers in Stop reading SharedValues in Live Markdown parsers to prevent an App Hang deadlock. The library can still deadlock the same way for any parser that touches the UI runtime, and nothing warns about it.

Where the library waits

On main at 0.1.369:

Proposed fix

  1. Warn and document (patch ready). In development, registerParser warns when the parser's closure captures a SharedValue. The README explains that parsers must not wait on the UI runtime. This would have caught the App bug, but it doesn't catch runOnUISync calls.
  2. Never wait on the runtime from the main thread without a limit. On a cache miss on the main thread, queue the parse in the background and wait up to a short timeout, for example 50 ms. On timeout, format with no ranges and apply styles again when the parse finishes. A deadlock then becomes one unformatted frame. This needs a design decision on the timeout and the fallback, plus native testing on both platforms.
  3. Android: read the cache under the lock and call nativeParse outside it, as the iOS fix did.

Item 1 is safe to ship now. Items 2 and 3 remove the cause and need native work.

Activity

  1. TaduJR commented on Nov 18, 2026

    @TaduJR
    Contributor

    @jmusial

    How is this going?

    Thanks!

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions