Skip to content

fix(app): keep OkHttp's IDN table out of the hostname method - #262

Open
Tarquinen wants to merge 2 commits into
devfrom
okhttp-idn-keep
Open

Tarquinen wants to merge 2 commits into
devfrom
okhttp-idn-keep

Conversation

@Tarquinen

@Tarquinen Tarquinen commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Play reports a native crash (SIGSEGV) in JIT-compiled OkHttp hostname code while the app builds a request URL. It hits many different arm64 phones and tablets on Android 13 to 16. All the reports I retraced are from 0.8.0 (build 380). The same JIT frame also shows up in Play crash groups from builds 39, 138 and 178, which I didn't retrace. R8 inlines OkHttp's IDN mapping table into the hostname method, and that is likely what ART's JIT trips on, though nobody has pinned down the exact defect.

Now R8 keeps OkHttp's IDN classes, so the table stays in its own class.

  • In the R8 benchmark build, the hostname method (_HostnamesCommonKt.toCanonicalHost) shrinks from 1,870 to 651 code units and no longer loads the table's three strings. Those now sit in IdnaMappingTableInstanceKt's initialiser, and IdnaMappingTable is a class again instead of being removed.
  • The APK grows by 16 KB (dex by 1.4 KB).
  • Others report the same thing. This post describes the crash and this rule. NPE in internal.idn.IdnaMappingTable.findRangesOffset lysine-dev/okhttp#8574 is a similar Java NPE in the same table code, with no established shared cause, and one reporter there saw hundreds of weekly crashes stop after keeping the table classes. In [firebase-perf] Native SIGSEGV crash in network instrumentation affecting multiple SDKs firebase/firebase-android-sdk#7681, someone with the same JIT trace saw their crashes drop to zero after the same kind of rule.
  • The cause is likely, not confirmed. I couldn't reproduce the crash on the x86_64 emulator, and every report is arm64. A unit test can't cover R8 output running on a device. Watch this crash signature on the first release that contains the rule before closing the issues.

The R8 benchmark build starts, connects to session-lab and opens a session on the emulator, and scripts/check.sh passes. Nothing visible changes.

Part of #245 and #249

Play reports a native crash (SIGSEGV) in JIT-compiled OkHttp hostname code
while building request URLs, on many arm64 devices. R8 inlines OkHttp's IDN
mapping table and its large string constants into the hostname method, which
ART's JIT likely miscompiles. Keeping the okhttp3.internal.idn classes leaves
the table in its own class.

In the R8 benchmark build the hostname method drops from 1,870 to 651 code
units and no longer loads the table strings; the APK grows by 16 KB. The
benchmark build starts, connects to session-lab and opens a session on the
emulator, and scripts/check.sh passes. The crash itself couldn't be reproduced
(x86_64 emulator, arm64 reports), so the next release's crash numbers are the
proof.

Part of #245 and #249
The comment above the rule no longer states the crash's cause as fact, and the
release build type's comment now mentions proguard-rules.pro. Comment-only
change; the rule is unchanged. Checked with scripts/check.sh :app.

Part of #245 and #249

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant