[PR #331] [MERGED] Fix: Collection was modified exception #862

Closed
opened 2025-12-29 08:33:48 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/331
Author: @theramis
Created: 8/22/2019
Status: Merged
Merged: 8/22/2019
Merged by: @StefH

Base: masterHead: master


📝 Commits (1)

  • f80debc Convert collection into a new list before enumerating

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 src/WireMock.Net/Server/FluentMockServer.LogEntries.cs (+1 -1)

📄 Description

Problem

We are using wiremock as part of our tests and we found that if we have tests running in parallel we sometimes get an error when calling the FindLogEntries method.

Error

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

Potential Solution

This is my quick attempt at fixing the above issue. By convert the collection into a new list it shouldn't throw an error if the LogEntries collection is updated.
From a quick google around the ToList method itself isn't thread safe either though. So its possible that while the ToList method is creating a copy, it fails due to the original collection getting changed.

Thoughts?
@StefH


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/wiremock/WireMock.Net/pull/331 **Author:** [@theramis](https://github.com/theramis) **Created:** 8/22/2019 **Status:** ✅ Merged **Merged:** 8/22/2019 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`f80debc`](https://github.com/wiremock/WireMock.Net/commit/f80debc94d677971fb8ce76f5afcf55090222fe5) Convert collection into a new list before enumerating ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/WireMock.Net/Server/FluentMockServer.LogEntries.cs` (+1 -1) </details> ### 📄 Description ## Problem We are using wiremock as part of our tests and we found that if we have tests running in parallel we sometimes get an error when calling the `FindLogEntries` method. **Error** ``` System.InvalidOperationException: Collection was modified; enumeration operation may not execute. ``` ## Potential Solution This is my quick attempt at fixing the above issue. By convert the collection into a new list it shouldn't throw an error if the `LogEntries` collection is updated. From a quick google around the `ToList` method itself isn't thread safe either though. So its possible that while the `ToList` method is creating a copy, it fails due to the original collection getting changed. Thoughts? @StefH --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 08:33:48 +01:00
adam closed this issue 2025-12-29 08:33:48 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#862