Skip to content

fix(synology): await producer thread shutdown before returning from uploadVideoChunks - #1494

Closed
alexeyqu wants to merge 1 commit into
masterfrom
fix/synology-producer-thread-shutdown
Closed

fix(synology): await producer thread shutdown before returning from uploadVideoChunks#1494
alexeyqu wants to merge 1 commit into
masterfrom
fix/synology-producer-thread-shutdown

Conversation

@alexeyqu

@alexeyqu alexeyqu commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

producerFuture.cancel(true) requests interruption but returns immediately, leaving the producer thread alive after createVideo returns. On resource-constrained CI runners, this races with Mockito's post-test stub validation, causing CreateMedia VideoModel tests to flake as SKIPPED.

Added producerFuture.get(5, TimeUnit.SECONDS) after the cancel so the method only returns once the producer has actually stopped. CancellationException and timeout are swallowed -- both mean the producer is done or on its way out.

Fixes the flaky test (see Gradle CI attempts on current master branch)

@simonxander

Copy link
Copy Markdown
Collaborator

The added get(5, TimeUnit.SECONDS) doesn't actually wait for the producer - it needs to come before cancel().

According to the CompletableFuture.get(long, TimeUnit) docs , get() throws CancellationException if the future was cancelled. Since producerFuture.cancel(true) runs first and completes the future into the cancelled state immediately, the subsequent get throws CancellationException right away and gets swallowed — so it returns instantly without ever waiting for the producer thread to finish. The race condition still occurs even with these changes.

Suggested fix

} finally {
  consumerAborted.set(true);
  try {
    producerFuture.get(5, TimeUnit.SECONDS);
  } catch (Exception ignored) {
    // Expected: CancellationException if cancelled, or timeout -- producer is stopping
  }
  producerFuture.cancel(true);
}

@alexeyqu

Copy link
Copy Markdown
Collaborator Author

@simonxander thank you! However, this PR didn't fix the flaky test.

After some discovery around #1495 I found the issue is test JVM OOM-ing during the test suite for Synology.

#1498 is the proposed temporary fix to unblock the CI -- and kickstart the conversation around a more permanent fix.

This PR is no longer needed, closing.

@alexeyqu alexeyqu closed this Jun 22, 2026
@alexeyqu
alexeyqu deleted the fix/synology-producer-thread-shutdown branch June 22, 2026 23:52
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.

2 participants