Skip to content

Commit ffbe5ad

Browse files
jamesnroktclaude
andcommitted
fix(ci): join HandlerThreads after quitSafely to eliminate thread restart race
Add join(500) after quitSafely() in MessageManager.destroy() and KitManagerImpl.reset() so old threads are fully dead before new ones are created in the next test's startMParticle(). This eliminates the "Thread starting during runtime shutdown" race on API 28 emulators. Also revert instrumented-tests.yml timeout_minutes default from 30 to 20 — the hang is in test execution, not emulator boot. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a256ed3 commit ffbe5ad

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

.github/workflows/instrumented-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
timeout_minutes:
1919
required: false
2020
type: number
21-
default: 30
21+
default: 20
2222

2323
permissions:
2424
contents: read

android-core/src/main/java/com/mparticle/internal/MessageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,12 @@ public void disable() {
10481048
public static void destroy() {
10491049
if (sMessageHandlerThread != null) {
10501050
sMessageHandlerThread.quitSafely();
1051+
try { sMessageHandlerThread.join(500); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); }
10511052
sMessageHandlerThread = null;
10521053
}
10531054
if (sUploadHandlerThread != null) {
10541055
sUploadHandlerThread.quitSafely();
1056+
try { sUploadHandlerThread.join(500); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); }
10551057
sUploadHandlerThread = null;
10561058
}
10571059
// Do NOT call startThreads() here — new threads are started lazily when MParticle.start()

android-kit-base/src/main/java/com/mparticle/kits/KitManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ public void onConsentStateUpdated(final ConsentState oldState, final ConsentStat
13361336
public void reset() {
13371337
if (kitHandlerThread != null) {
13381338
kitHandlerThread.quitSafely();
1339+
try { kitHandlerThread.join(500); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); }
13391340
kitHandlerThread = null;
13401341
mKitHandler = null;
13411342
}

0 commit comments

Comments
 (0)