Do not return null objects in getAll of the InMemoryRequestJournalStore #2508
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.
Under heavy load it's possible that
serveEvents.get()
is called with anUUID
that doesn't exist anymore in theMap
. The reason for this is that the spliatator (required forstream()
) of theConcurrentLinkedDeque
is weakly consistent. This means that it's not guaranteed that an element that is currently processed in aStream
still exists in the collection. So under heavy load it may happen, that one thread reads an element of theConcurrentLinkedDeque
. Then this thread gets paused and another thread gets activated which than completely runs theremove
method of theInMemoryRequestJournalStore
. Now the first thread gets activated again and calls theget
method of theserveEvents
with anUUID
that doesn't exist anymore in theMap
which results in anull
value. As the remaining code doesn't expectnull
values in theStream
they should be filtered out. Another solution would be tosynchronize
the code of theInMemoryRequestJournalStore
but this would slow down the whole thing dramatically.I haven't added any tests for this as it's hard to reproduce a concurrency issue.
References
Submitter checklist
#help-contributing
or a project-specific channel like#wiremock-java