Skip to content

[#868] Release the import/export context before notifying the initialize task - #869

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issue-868-release-ie-context-before-notify
Aug 19, 2026
Merged

vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issue-868-release-ie-context-before-notify

Conversation

@vharseko

Copy link
Copy Markdown
Member

Fixes #868.

ReplicationDomain terminated a total update by notifying the initialize task first and releasing the import/export context afterwards. Between the two, ieRunning() still reports true, so anything reacting to the completion — the task thread of a real InitializeTask, or ReplicationDomainTest.errorMsgFromSameMillisecondTerminatesPendingInitialize woken up on the listener thread's notification — can see its own total update rejected as a simultaneous import/export.

That window is what made the test fail in CI (run 32124729058, ubuntu-latest/26); the other 8 matrix jobs of the same run were green.

What changed

All three import-termination paths now go through one helper that releases the context before notifying the task:

private void completeInitializeTask(ImportExportContext ieCtx)
{
  releaseIEContext();
  if (ieCtx.initializeTask instanceof InitializeTask)
  {
    ((InitializeTask) ieCtx.initializeTask).updateTaskCompletionState(ieCtx.getException());
  }
}

The reordering is safe: ieCtx stays reachable through the local reference and getException() reads that object, not the AtomicReference.

In initialize() the notification also moves from the try into the finally that releases the context. It used to sit after broker.publish(errorMsg), so a failure while notifying the exporter skipped updateTaskCompletionState() altogether and left the task waiting forever — the failure mode fixed in #861/#864. The "update the task must be the last thing" requirement refers to broker.reStart(false), which runs before this block, so it still holds. As a side effect the task is now also notified when the import fails before initFromTask is assigned (e.g. initializeCounters() throwing), where it previously got no notification at all. Remote-initiated imports carry no local task and are unaffected.

Tests

No test change: releaseIEContext() is a volatile write and the task notification gives happens-before, so the existing assertion becomes deterministic instead of racy. Relaxing it into a poll would have hidden the defect.

mvn -pl opendj-server-legacy -Pprecommit verify -Dit.test=ReplicationDomainTest — 12/12 green locally.

…otifying the initialize task

ReplicationDomain terminated a total update by notifying the initialize task
first and releasing the import/export context afterwards. Anything reacting
to that completion - the task thread of a real InitializeTask, or
ReplicationDomainTest.errorMsgFromSameMillisecondTerminatesPendingInitialize
woken up by the listener thread - could still observe ieRunning() as true and
get its own total update rejected as a simultaneous import/export.

Release the context first and notify the task afterwards, from a single
completeInitializeTask() helper shared by the three termination paths: the
ErrorMsg answering a pending initialization, the stalled-request watchdog and
the end of an import from a remote replica.

In that last path the notification also moves into the finally block that
releases the context: it was previously skipped when notifying the exporter
failed, leaving the task waiting forever.

Fixes OpenIdentityPlatform#868
@vharseko
vharseko requested a review from maximthomas August 18, 2026 12:37
@vharseko vharseko added bug replication concurrency Thread-safety / race-condition bugs java labels Aug 18, 2026
@vharseko
vharseko merged commit 4cd9716 into OpenIdentityPlatform:master Aug 19, 2026
18 checks passed
@vharseko
vharseko deleted the issue-868-release-ie-context-before-notify branch August 19, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug concurrency Thread-safety / race-condition bugs replication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky total update termination: the import/export context is released after the initialize task is notified

2 participants