Providing an idle publisher to resolve race condition #5993
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.
Motivation and Context
This test had two separate race conditions:
exceptionOccurred
function and the Subscriber'sfailed()
method both race to complete the completeablefuture exceptionally resulting in:This can be solved by making the assertion more relaxed. This test is meant to test the delete file behavior, and not the exception handling. I believe this exception assertion that was added in the
stubException
helper function was to enforce the contract (an exception is propagated when the file transformer is terminated). This race condition caused that the specific exception could not be guaranteed.preformWrite
finished writing before the Transformer'sexceptionOccurred
handler was able to complete the future exceptionally:The fix replaces the original
SdkPublisher
that emits data withFlowable.just(content, content)
with an idle publisher that emits data but never completes.The original publisher would emit and immediately complete, creating a race between normal completion and exception handling. The idle publisher keeps the stream open, while the exception handling path has time to execute before completion.
Testing
Created a
@RepeatedTest
wrapper with a 1000 executions to check for failure rates. The test was failing 0.4-1.2% of tests. After the fix I see a 0% failure rate.Added logging to each handler of the FileSubscriber and the Transformer to observe the race conditions. For example: