Repository navigation
Description
Apple's ADI library is initialised once per LocalAnisette instance, and a new instance is
built every time anything asks for Anisette. The library itself is process-global, so the second
and every subsequent initialisation re-enters an ADI that is already initialised — and it can
segfault.
Caught in CI, which aborted a run at 335 of 564 tests. The logcat artefact has the stack:
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x234546
pid: 1889, tid: 1917, name: RxCachedThreadS
#00 pc 0000000000234546 <unknown>
#01 pc 00000000001c5f0a .../anisette/lib/x86_64/libstoreservicescore.so
#02 pc 00000000001c5cc5 .../anisette/lib/x86_64/libstoreservicescore.so
#03 pc 00000000001c4bad .../anisette/lib/x86_64/libstoreservicescore.so
#04 pc 00000000001d23a6 .../anisette/lib/x86_64/libstoreservicescore.so
#05 pc 00000000000263d6 libopentagviewer.so (Java_..._NativeAdi_callWithPath+86)
#12 AdiLibrary.withPath
#18 AdiLibrary.initialise
#24 LocalAnisette.load
#30 LocalAnisette.ensureReady
#36 AnisetteStatus.of
NativeAdi.callWithPath is ADILoadLibraryWithPath or ADISetProvisioningPath.
The guard is per-instance; what it guards is per-process
// LocalAnisette
public synchronized boolean ensureReady() {
if (this.adi != null) {
return true; // <- only ever true for an instance that already loaded
}
...
load(libraryDir);
}// AppDependencies
anisetteFactory = LocalAnisette::new; // <- a fresh instance every callNeither AdiLibrary.open nor AdiLibrary.initialise caches anything. open re-dlopens (benign
— refcounted, same handle) and re-resolves the symbols; initialise then calls
ADILoadLibraryWithPath, ADISetProvisioningPath and ADISetAndroidID unconditionally.
So every caller re-initialises Apple's library in a process where it is already initialised.
Why this is not only a test problem
AppDependencies.anisette(...) is called on the way to restoring a session — so once per
MapsActivity creation. That activity is recreated by AppCompat on:
- a theme change
- a language change
- a map provider change
- the system-colours toggle
- the Apple-devices toggle
Somebody flicking dark mode on and off a few times therefore re-initialises Apple's native
library a few times, in one process, from a background thread.
Not observed in the app — only under test, where ~560 activity creations happen in one
process and the odds compound. That is inference from the mechanism rather than a reproduction,
and worth saying plainly. But the mechanism is not in doubt, and the consequence in the app would
be a hard native crash with no Java stack, which is about the worst failure this app could have.
Impact under test, which is measurable
A native crash kills the instrumentation process. The run does not fail — it stops, and every
remaining test is reported as never having run. That is the intermittent whole-suite abort this
repo has been living with: it presents as two arbitrary test names plus Process crashed, where
the names are whichever tests were in flight and have nothing to do with the cause.
Worked around in the test suite already, by having the map fixture use FakeAnisetteSource the
way the login-flow tests always have. That removes the trigger from the suite; it does not fix
the app.
Fix direction
Hold the initialised AdiLibrary once per process rather than once per LocalAnisette, so a
second caller reuses it instead of re-initialising.
Care needed, because this is rule 4 territory and a mistake here surfaces as authentication
failing hours from the cause:
- A second caller could legitimately want different state. The provisioning path and the
hardware profile come from stored identity and are stable in practice, but "in practice" is not
the same as enforced. If they differ, reusing silently is its own bug — that case should be
loud rather than papered over. ADIProvisioningErasegenuinely needs to re-initialise. Whatever caches has to have a way
to be invalidated, or resetting Anisette stops working.- Thread safety has to be process-wide too, not per instance, since the whole point is that
two threads can now reach it.
Worth a test that asks for Anisette twice and asserts the library is initialised once — the
current behaviour would fail it, which is the point.
Related
- #133 — the discarded-
AppleAccount
leak. Different cause; I guessed at that one first and was wrong. AGENTS.mdrule 4, on the Anisette constraints this sits inside.
🤖 Written by Claude Code
Activity
wanderdev0 commentedon Aug 22, 2026
The mechanism is worse than described above: it is not only repeated initialisation, it is
concurrent initialisation, including two threads writing the same files.
Caught in another aborted run.
TheMapDrawsWhatIsStoredTeststores a session that cannot berestored — the ordinary expired-session state — and the logcat shows two threads unpacking and
loading Apple's libraries at the same time:
Two threads, same paths, same process.
How two arrive at once
It is the sequence this app takes whenever a session has gone bad:
MapsActivitystarts restoring, and asks for Anisette on an Rx thread — realLocalAnisettenumber one.
AppleLoginActivity.AnisetteStatus.of(AppDependencies.anisette(...))— realLocalAnisettenumber two, while the first is still working.
ensureReady()issynchronized, which looks like it covers this and does not: the lock is onthe instance, and these are two instances. There is no mutual exclusion at all.
Why that is worse than repeated init
Repeated sequential initialisation re-enters an already-initialised ADI, which is bad. Concurrent
initialisation adds two more failure modes:
.sofiles.AdiLibraryFetcherunpacks to a fixed path. Areader can
dlopena file another thread is part-way through writing, and a half-writtenshared object is not a shared object.
ADILoadLibraryWithPath/ADISetProvisioningPathon one nativelibrary that has no reason to be thread-safe and is not ours to make so.
What this means for the fix
Whatever holds the initialised
AdiLibraryhas to be process-wide and locked process-wide —the point is precisely that two threads reach it. A per-instance
synchronizedis what createdthis. The download and unpack need covering too, not just the initialise: the race starts before
ADI is ever called.
Reachability in the app
The three-step sequence above is not contrived — it is what an expired session does today, and
the session-recovery work in #134 makes that path more travelled rather than less. Still only
observed under test, but the trigger is an ordinary user state rather than 560 activity
creations in one process.
🤖 Written by Claude Code
Load Apple's ADI library once per process, not once per caller
Keep Apple's real ADI library out of four more tests
Keep Apple's real ADI library out of four more tests
Load Apple's ADI library once per process, not once per caller
Stop Apple's library crashing the app on every launch