Skip to content

AlertStateStoreTest hung for over 30 minutes in one full local run; cause not yet proven #359

Open

Description

@nofuturekid

What happened

During a full ./scripts/local-ci.sh run (Gradle in the CI container, task :app:testDirectDebugUnitTest) the test AlertStateStoreTest.remove_forgets_only_that_server did not finish for about 34 minutes. The run was killed by hand. Later runs of the same commit passed (a full run with 433 tests, and later full runs on other branches with 579 and 582 tests).

Where in the run it happened

The test results of a full run show the order: test classes run one after another in one JVM, in name order. AlertStateStoreTest is the tenth class, reached about 16 seconds into the test JVM, and the hung method is the first of the class, right after its setUp. Nine classes ran before it; four of them use the same DataStore (one object per Robolectric sandbox): AlertCheckRunnerTest, AlertCheckWorkerTest, AlertSchedulerTest, AlertSettingsStoreTest. The hung container was the only running container at that time.

What the thread dump shows

Taken with jstack 2073 s after the test JVM started:

  • SDK 35 Main Thread (the Robolectric main thread, which runs the test) is parked in BlockingCoroutine.joinBlocking, called from the runBlocking that opens the test body. @Before had already finished (RunBefores is on the stack), so the stall is in the body.
  • All seven DefaultDispatcher workers (which serve Dispatchers.IO, the scope of the DataStore) are idle and parked. No thread is in DataStore, file I/O, WorkManager or Room code. No thread holds a lock another one waits for. The JVM reported no deadlock.
  • Test worker waits only for the Robolectric main thread; the Gradle worker threads wait only for the test worker.

So nothing is blocked on a resource and nothing can run: a coroutine is suspended and the event that would resume it never came. A thread dump cannot show which coroutine or what it waits for.

The cause is unknown

Two hypotheses are open:

  • H1: an edit whose caller dispatcher cannot run keeps DataStore's coordinator mutex locked. DataStore runs the transform of every edit in the coroutine context of the caller, inside its serial write actor, while the actor holds its lock. If an edit is started from a dispatcher that does not run (for example Dispatchers.Main while the Robolectric main thread is blocked in runBlocking), the transform is posted to a looper that never runs, the lock stays held, and every later edit in that JVM waits for ever. This was reproduced in a throw-away test: the second edit never completes, the main thread is parked in joinBlocking, all workers are idle, and the dump has the same shape as the one above; running the looper releases the edit. For H1 to be true, one of the four earlier DataStore classes must have started such an edit and left it behind, and it must have entered the write actor after setUp: the clear() edit at the end of setUp is unconditional and it finished (RunBefores was on the stack), so the blocking edit started from a coroutine that was still running after it. No code that runs before AlertStateStoreTest was found to do that (checked in data/alerts and the root test classes), so the trigger is unknown.
  • H2: a resumption into the main thread's blocking event loop (the runBlocking of the test) never arrives, and nothing holds the mutex. No mechanism for this has been found either.

Ruled out:

  • A second Gradle container on the shared Gradle volume. The hung container was the only one running. The DataStore file lives in Robolectric's temp directory inside the container, not on the shared volume, and the DataStore used here (SingleProcessCoordinator) takes no file lock. When two containers do collide on the shared volume, Gradle fails at start-up with a cache lock error; it does not stall a test.
  • I/O, fsync or lock stalls, thread starvation, an exhausted Dispatchers.IO: no thread is busy or blocked.
  • A plain race in runBlocking plus DataStore: 20 000 rounds of 5 store operations (100 000 operations) on the Robolectric main thread did not stall once, and 9 fresh-container runs of only this class did not either.

Can the shipped app hit it?

No path was found. The app's main code never blocks the main thread (runBlocking does not occur in app/src/main), edits started from viewModelScope run their transform on a live looper, and the background check (CoroutineWorker, Dispatchers.Default) runs its transforms on Dispatchers.Default. H1 needs a caller whose dispatcher cannot run, which the app does not create. Not proven by a test on the production path, because no stall could be reproduced there.

Next step

The linked pull request makes every test class that uses the DataStore fail fast on a stall: if a test has not finished after 60 s it writes a dump and ends the test JVM. The dump now holds the watched test classes started so far (in order; classes without the rule are not listed), every live coroutine with state, dispatcher, suspension point, creation stack and the watched class during which it was created (every coroutine named in the summary in full, the others newest first up to a cap), which coroutine holds the DataStore mutex and where it is suspended, what the test's runBlocking waits on, the main looper queue and the DataStore internals. H1 shows as a coroutine holding the mutex suspended in transformAndWrite, a locked mutex and an edit caller on a dispatcher that is not served (second shape: the test's own transform lost on its own runBlocking, one holder and the only caller on the BlockingEventLoop). H2 shows as a suspended runBlocking, no holder, an unlocked mutex and no edit caller. An empty event loop queue does not separate them (it is empty in the H1 validation run too). A creation stack that points into an earlier test class names the class that leaked; when it names no test (a coroutine started from another coroutine), the dump's per-coroutine "created during" line gives the watched class.

What the dump cannot tell: which of several edit callers on unserved dispatchers is in flight, whether in H2 the answer was never completed or completed with a lost resumption, and it can miss a coroutine on an abandoned dispatcher that nothing references (the mutex state and actor queue are still shown).

If you see a stall: copy app/build/stall-dumps and app/build/test-results out of the checkout (or download the test-report artifact of the failed CI job) BEFORE any rerun, attach them to this issue, and do not rerun first. A rerun deletes them.

This issue stays open until a dump explains a recurrence.

Activity

  1. added this to the 0.1.49 milestone on Nov 13, 2026
  2. added
    bug
    on Nov 13, 2026
  3. nofuturekid commented on Nov 13, 2026

    @nofuturekid
    CollaboratorAuthor

    A second observation from the same day, from the work on #361 (Settings section for alerts): two targeted test runs hung there as well, and that builder found the mechanism in its own new tests. The test thread is the Robolectric main thread; DataStore transforms started by a view model run on the main dispatcher; a test that blocks the main thread while reading settings therefore waits for a transform that can only run on the thread it is blocking. The tests were changed to wait on what the screen shows and to idle the looper; no product code changed.

    This is hypothesis H1 occurring in real test code, not only in the constructed experiment. It does not prove that the original 34 minute hang had the same cause: no view model is involved in AlertStateStoreTest, and a main-dispatched edit left over from an earlier class has not been found. It does make H1 the more likely of the two, and it names what to look for in the next dump: a coroutine created by a view model scope or another main-dispatched scope with an edit in flight.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions