You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Main thread waits on the Live Markdown runtime with no limit, so a parser that touches the UI runtime can hang the app #824
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:
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.
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.
iOS: the component view formats through RCTMarkdownUtils.mm:20-35, which calls parse: on the main thread when the cache misses. The guard added in Fix main thread hang on iOS (RCTMarkdownUtils.mm:56-79) only covers the shadow node's measure path. The cache misses on every new parserId, on new text, and after prepareForRecycle. updateProps is the path in the hang trace.
Android:MarkdownParser.parse is synchronized and calls nativeParse → runSync on the UI thread with no guard. It also holds the Java lock while it waits on the runtime, which is the pattern that PR removed on iOS.
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.
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.
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
TaduJR commentedon Nov 18, 2026
@jmusial
How is this going?
Thanks!