FUTO Notes 1.4.1 — the backspace crash
A post-mortem on the one crash that had haunted the app since launch, and the shield between IMEs and Chromium that fixed it.
Ever since FUTO Notes launched internally, there has been one bug that has haunted me. With 1.4.1, it has been squashed for good.
The bug
On one tester’s Motorola phone running Android 11, all he had to do was open the app, tap the button to create a new note, then once the keyboard came up in the body of the note, hit backspace once. Within a couple of seconds, the app would crash.
A few weeks ago I had him try again, but this time with a different keyboard. Aha! The crash did not happen on Gboard. Progress. I still couldn’t tell what was going on, though.
Debugging
This was the worst kind of bug because I could not replicate it. Oddly, his phone was the only device where we saw this issue. I tried to replicate this crash on my emulator as well as a similar Motorola device. No dice.
I added crash reporting and got nothing useful. I added deeper crash reporting
and still couldn’t figure out the root cause. Luckily, I was able to get him to
reproduce the crash while plugged in to my computer running adb logcat, which
helped immensely. This helped me find where the crash was occurring and properly
diagnose the cause of the bug.
I still don’t know why I could not replicate this bug. Best guesses: Chromium has this program named Finch where they run experiments on Chromium, so two people could be hitting different code paths. Or perhaps he was running an old version of FUTO Keyboard? Or had different settings/features enabled? Perhaps it was just a quirk with his specific processor, like a very specific race condition?
The cause
When you backspace in an empty field in FUTO Notes, FUTO Keyboard asks for the surrounding text so it can backspace properly. This is helpful for deleting special characters and emojis. The problem is that this fails a Chrome assertion when there is no surrounding text, and this triggers a SIGTRAP that kills the renderer process, which was causing the whole app to crash.
Other keyboards like Gboard do not ask for surrounding text when the field is empty, it seems. That’s why we were only seeing this with FUTO Keyboard.
The fix
I essentially added a shield between IMEs like FUTO Keyboard and Chromium to intercept potentially problematic requests. So now when FUTO Keyboard asks for the surrounding characters while in an empty note, my Kotlin shield intercepts the question and answers it without telling Chromium.
Additionally, we now handle renderer crashes more elegantly.