Native crash (SIGSEGV in getSuggestionsNative) when typing with a multilingual secondary language
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 25/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- Kotlin
- Étoiles
- 1k
- Forks
- 59
- Merge moyen
- 14 h 9 min
- PR mergées (30 j)
- 56
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de LeanBitLab/LeanType
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
LeanBitLab/LeanType#760 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 62/100
LeanBitLab/LeanType#763 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 Une demi-journée Accessibilité débutants 62/100
LeanBitLab/LeanType#762 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 Une demi-journée Accessibilité débutants 70/100
LeanBitLab/LeanType#761 ·
Les mainteneurs répondent en général sous 1 jour
-
[Feature Request] Add "Swipe left on delete key to delete word by word" gesture (like SwiftKey)Ouverteenhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
LeanBitLab/LeanType#757 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de LeanBitLab/LeanType
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
liberation-data/drivine4j#547 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
ccch1mneyyy/dsh-Go#381 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
wangzan101/Mika#227 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
theopenconversationkit/tock#2136 ·
Les mainteneurs répondent en général sous 1 jour
-
App asks for diameter for emergency=hydrant + water_source=groundwater. But should probably not.Ouvertefeedback required
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
streetcomplete/StreetComplete#7354 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour