FindLogEntries regression #661

Closed
opened 2025-12-29 15:30:07 +01:00 by adam · 2 comments
Owner

Originally created by @rinkeb on GitHub (Jan 9, 2025).

Originally assigned to: @StefH on GitHub.

Describe the bug

It looks like 1.6.11 has a regression in method WireMockServer.FindLogEntries. After NuGet upgrade, this exception is sometimes thrown:

 ---> System.ArgumentException: Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray')
   at System.Array.CopyImpl(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
   at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at WireMock.Server.WireMockServer.FindLogEntries(IRequestMatcher[] matchers)

This seems to happen intermittently, most likely due to concurrency.

Looking at this change , I suspect that the apparent regression is caused by the change from ToList() to ToArray().
When new log entries are added to _options.LogEntries while creating the array, the input collection becomes larger than the allocated array during copying. Previously the target list could grow, but the array cannot.

Expected behavior:

No exception.

Test to reproduce

Add items to _options.LogEntries during the call to _options.LogEntries.ToArray()

Using .NET 9 SDK and Runtime

Originally created by @rinkeb on GitHub (Jan 9, 2025). Originally assigned to: @StefH on GitHub. ### Describe the bug It looks like 1.6.11 has a regression in method `WireMockServer.FindLogEntries`. After NuGet upgrade, this exception is sometimes thrown: ```System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray') at System.Array.CopyImpl(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length) at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at WireMock.Server.WireMockServer.FindLogEntries(IRequestMatcher[] matchers) ``` This seems to happen intermittently, most likely due to concurrency. Looking at [this change](https://github.com/WireMock-Net/WireMock.Net/commit/485f7ad95249399771588945ad166935133e934f#diff-71abb5ad3aa042095252fa5c34518b8b2ca2c2fdc336cfc59d1dc66f35212a2eR32) , I suspect that the apparent regression is caused by the change from `ToList()` to `ToArray()`. When new log entries are added to `_options.LogEntries` while creating the array, the input collection becomes larger than the allocated array during copying. Previously the target list could grow, but the array cannot. ### Expected behavior: No exception. ### Test to reproduce Add items to `_options.LogEntries` during the call to `_options.LogEntries.ToArray()` ### Other related info Using .NET 9 SDK and Runtime
adam added the bug label 2025-12-29 15:30:07 +01:00
adam closed this issue 2025-12-29 15:30:07 +01:00
Author
Owner

@StefH commented on GitHub (Jan 9, 2025):

Thanks for noticing.

Can you try preview 1.6.11-ci-19560 ?
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Jan 9, 2025): Thanks for noticing. Can you try preview `1.6.11-ci-19560` ? https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@rinkeb commented on GitHub (Jan 9, 2025):

@StefH cannot reproduce the issue anymore, so it looks like its working.

@rinkeb commented on GitHub (Jan 9, 2025): @StefH cannot reproduce the issue anymore, so it looks like its working.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#661