Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not return null objects in getAll of the InMemoryRequestJournalStore #2508

Merged

Conversation

coder-hugo
Copy link
Contributor

Under heavy load it's possible that serveEvents.get() is called with an UUID that doesn't exist anymore in the Map. The reason for this is that the spliatator (required for stream()) of the ConcurrentLinkedDeque is weakly consistent. This means that it's not guaranteed that an element that is currently processed in a Stream still exists in the collection. So under heavy load it may happen, that one thread reads an element of the ConcurrentLinkedDeque. Then this thread gets paused and another thread gets activated which than completely runs the remove method of the InMemoryRequestJournalStore. Now the first thread gets activated again and calls the get method of the serveEvents with an UUID that doesn't exist anymore in the Map which results in a null value. As the remaining code doesn't expect null values in the Stream they should be filtered out. Another solution would be to synchronize the code of the InMemoryRequestJournalStore 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

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • Recommended: If you participate in Hacktoberfest 2023, make sure you're signed up there and in the WireMock form
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@coder-hugo coder-hugo requested a review from a team as a code owner November 29, 2023 09:00
@tomakehurst
Copy link
Member

Despite the lack of tests (which I agree are hard to reliably do) I think this looks safe to merge.

@tomakehurst tomakehurst merged commit be87fe5 into wiremock:master Dec 4, 2023
7 checks passed
@coder-hugo coder-hugo deleted the feature/fix-concurrency-issues branch December 5, 2023 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants