PHOENIX-7960 ReplicationLogGroup.close() racing init() can swallow the disruptor halt alert, leaking the writer#2579
Open
tkhurana wants to merge 2 commits into
Open
Conversation
…e disruptor halt alert, leaking the writer A close() that immediately follows init() could halt() the disruptor before its consumer thread entered BatchEventProcessor.run(). run()'s opening clearAlert() then wiped the alert raised by halt(), the wait loop parked forever, and onShutdown never ran, so the underlying writer was never closed. This surfaced as a flaky testClose (Mockito "wanted but not invoked: close()") and latently affects every recreateLogGroup()/tearDown() that closes a zero-append group right after creation. Add a startedLatch counted down in LogEventHandler.onStart() and await it (bounded by shutdownTimeoutMs) in close() before disruptor.shutdown(), so the consumer is guaranteed past clearAlert() when halt() raises the alert. Extract createDisruptorExecutor() as a @VisibleForTesting seam and add testCloseImmediatelyAfterInitClosesWriterWhenConsumerStartsLate, which delays the consumer start to force halt() into the pre-clearAlert window and verifies the writer is still closed.
…start/shutdown race test - Add @test(timeout = 60000) so a regression reintroducing the swallowed halt() alert fails fast instead of spinning until shutdownTimeoutMs. - Correct comment: YieldingWaitStrategy spins, it does not park.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A ReplicationLogGroup.close() that immediately follows init() can halt() the disruptor before its consumer thread has entered BatchEventProcessor.run(). run()'s opening clearAlert() then wipes the alert raised by halt(), the wait loop parks forever, and onShutdown() never runs — so the underlying ReplicationLogWriter is never closed.