Native crash (SIGSEGV in getSuggestionsNative) when typing with a multilingual secondary language
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Start with DictionaryFacilitatorImpl.getSuggestionResults(), where secondary-dictionary queries run in scope.launch and are awaited for 120 ms, then BinaryDictionary.getSuggestions(), where only getTraverseSession() is synchronized and the native call is not. The work is to confirm that overlapping queries share one DicTraverseSession and then make access to that session safe; the reporter already has a candidate fix. Done means no SIGSEGV under overlapping queries, which needs a device or a concurrency reproduction.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
With a secondary language added via Multilingual typing (German + English (US), both main dictionaries installed), the keyboard process sometimes crashes in native code (SIGSEGV, null pointer dereference in libjni_latinime.so). For us it happened right after tapping the clipboard suggestion and when typing fast.
Backtrace (shortened):
F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x11 in tid 10828 (DefaultDispatch)
F DEBUG : Cause: null pointer dereference
F DEBUG : #00..#04 libjni_latinime.so
F DEBUG : #11 com.android.inputmethod.latin.BinaryDictionary.access$getSuggestionsNative
F DEBUG : #24 com.android.inputmethod.latin.BinaryDictionary.getSuggestions
F DEBUG : #30 helium314.keyboard.latin.dictionary.ReadOnlyBinaryDictionary.getSuggestions
F DEBUG : #35 helium314.keyboard.latin.dictionary.DictionaryCollection.getSuggestions
F DEBUG : #38 helium314.keyboard.latin.DictionaryFacilitatorImpl.getSuggestions
F DEBUG : #49 helium314.keyboard.latin.DictionaryFacilitatorImpl$getSuggestionResults$1.invokeSuspend
F DEBUG : #53 kotlinx.coroutines.DispatchedTask.run
Cause (from reading the code)
DictionaryFacilitatorImpl.getSuggestionResults() queries the secondary dictionary groups in scope.launch {} on a background thread and waits for them only up to await(120, TimeUnit.MILLISECONDS) (reduced from 500 ms in 05023da). If a query takes longer, the next keystroke starts a new query on the same dictionary while the previous one is still running.
Both queries use the same DicTraverseSession (same session id). Its Java buffers (mInputCodePoints, mPrevWordCodePointArrays, ...) and the native session are shared. BinaryDictionary.getSuggestions() only synchronizes the session lookup in getTraverseSession(), not the native call, so two threads can run getSuggestionsNative() on the same native session at the same time.
Fix that works for us
Hold a lock on the session for the whole query in BinaryDictionary.getSuggestions():
val session = getTraverseSession(sessionId)
synchronized(session) {
// fill the session buffers, call getSuggestionsNative(..., session.getSession(), ...), read the results
}
(and pass session.getSession() instead of calling getTraverseSession(sessionId) a second time). We haven't seen the crash since. I can send a PR once we've tested it a bit longer.
To Reproduce
- Languages & Layouts → German → Multilingual typing → add English (US). Install the main dictionaries for both.
- Type fast, or copy some text and tap the clipboard suggestion right away.
- Occasionally the keyboard crashes and restarts. It depends on timing, so it doesn't happen every time.
Expected behavior
No crash.
App version & Flavor
Found in GlassType, my fork based on LeanType 4.3.0 (d634e26), standard flavor. BinaryDictionary.getSuggestions() is unchanged in current main (0e673e1), and getSuggestionResults() now waits even shorter (120 ms).
Device Info
- Model: Samsung Galaxy S23 Ultra (SM-S918B)
- OS version: Android 17
- 主要語言
- Kotlin
- 星號
- 1k
- 分支
- 59
- 平均合併
- 14 小時 9 分鐘
- 30 天內合併 PR
- 56
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
LeanBitLab/LeanType 的其他 Issue
-
enhancement
難度 5/5 一週以上 新手友好度 35/100
LeanBitLab/LeanType#766 ·
維護者通常 1 天內回覆
-
[Bug] Silence timeout doesn't close interface and start transcription; causes silent loss of dictated speech.可能已有人在做 @LeanBitLab 今天認領。 未關閉bug
LeanBitLab/LeanType#765 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 45/100
LeanBitLab/LeanType#764 ·
維護者通常 1 天內回覆
-
enhancement
難度 4/5 3-5 天 新手友好度 30/100
LeanBitLab/LeanType#757 · 7 則留言 ·
維護者通常 1 天內回覆
-
More suggestions based on version 1.0.1 of the CJK plugin可能已有人在做 @LeanBitLab 於 2 天前認領。 未關閉enhancement
難度 4/5 3-5 天 新手友好度 38/100
LeanBitLab/LeanType#754 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 LeanBitLab/LeanType 的全部 Issue
相似的 Issue
-
bug core p3
難度 2/5 1-3 小時 新手友好度 72/100
RunanywhereAI/runanywhere-sdks#1258 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
Kotlin-server-squad/vizcore#278 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
open-learning-exchange/myplanet#18484 ·
維護者通常 1 天內回覆
-
enhancement
難度 1/5 1 小時以內 新手友好度 90/100
Seb3thehacker/gearslip#71 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
ccch1mneyyy/dsh-Go#426 ·
維護者通常 1 天內回覆