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

FindLogEntries exception 'Destination array was not long enough' #1254

Closed
rinkeb opened this issue Feb 25, 2025 · 2 comments
Closed

FindLogEntries exception 'Destination array was not long enough' #1254

rinkeb opened this issue Feb 25, 2025 · 2 comments
Assignees
Labels

Comments

@rinkeb
Copy link

rinkeb commented Feb 25, 2025

Describe the bug

Intermittent exception when calling WireMockServer.FindLogEntries:

Message:

System.ArgumentException : Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray')

Stack Trace: 

Array.CopyImpl(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
List`1.CopyTo(T[] array, Int32 arrayIndex)
Enumerable.ToArray[TSource](IEnumerable`1 source)
WireMockServer.get_LogEntries()
WireMockServer.FindLogEntries(IRequestMatcher[] matchers)

This only seems to happen when log entries are being added to WireMockMiddlewareOptions.LogEntries during the call to FindLogEntries.

Expected behavior:

No exception should be thrown.

Test to reproduce

  • Call FindLogEntries while entries are added to source collection _options.LogEntries.

Other related info

It looks like the generic Enumerable.ToArray implementation called in public IReadOnlyList LogEntries => _options.LogEntries.ToArray(); for getting a snapshot of the log entries does not like it when the source collection grows while copying the items. A dedicated threadsafe ToArray implementation on ConcurrentObservableCollection might be the solution.

Related: #1234
Using version 1.7.2

@rinkeb rinkeb added the bug label Feb 25, 2025
@StefH StefH self-assigned this Feb 26, 2025
@StefH
Copy link
Collaborator

StefH commented Feb 26, 2025

"A dedicated threadsafe ToArray implementation on ConcurrentObservableCollection might be the solution"
--> Good suggestion !

@StefH
Copy link
Collaborator

StefH commented Feb 26, 2025

#1256

@StefH StefH closed this as completed Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants