Open progress conditionVariable when quitting internal thread.

If getProgress is blocking whilst the internal thread calls endInternal
(for error or success), the condition is never opened. Related to this,
onCompleted and onError are therefore never surfaced to the app.

progressState is accessed from application and internal threads, so
should be marked volatile to prevent a thread caching the value.

PiperOrigin-RevId: 565720184
This commit is contained in:
samrobinson 2023-09-15 10:47:16 -07:00 committed by Copybara-Service
parent fef16b05d9
commit c4fb755283

View File

@ -366,8 +366,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
internalHandler.post(internalHandlerThread::quitSafely); internalHandler.post(internalHandlerThread::quitSafely);
} }
// Update progress before opening variable to avoid getProgress returning an invalid combination
// of state and progress.
progressState = PROGRESS_STATE_NOT_STARTED;
transformerConditionVariable.open();
if (forCancellation) { if (forCancellation) {
transformerConditionVariable.open();
return; return;
} }