Skip to content

Fixed concurrent collection access crash#422

Merged
sandrohanea merged 1 commit into
sandrohanea:mainfrom
rodgers-r:main
Sep 5, 2025
Merged

Fixed concurrent collection access crash#422
sandrohanea merged 1 commit into
sandrohanea:mainfrom
rodgers-r:main

Conversation

@rodgers-r

Copy link
Copy Markdown
Contributor

The way the segment event handlers were being dispatched caused a rare exception if a new handler was added/removed by ProcessAsync:

Unhandled exception. System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at Whisper.net.WhisperProcessor.OnNewSegment(IntPtr state)
at Whisper.net.WhisperProcessor.OnNewSegmentStatic(IntPtr ctx, IntPtr state, Int32 nNew, IntPtr userData)

This patch fixes the crash by preventing concurrent access to the collection.

@sandrohanea

Copy link
Copy Markdown
Owner

Hello @rodgers-r ,
Indeed, it seems that the bug was there and also appeared in the past in the pipelines: https://github.com/sandrohanea/whisper.net/actions/runs/17191846947/job/48768577897.

Thanks for the patch!

@sandrohanea

Copy link
Copy Markdown
Owner

The other pipeline issues are not related to the PR and will be fixed in another PR, merging now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants