fixing race in Binder that can cause NullReferenceExceptions#3167
Merged
Conversation
RohitRanjanMS
approved these changes
Nov 19, 2025
mathewc
reviewed
Nov 19, 2025
mathewc
approved these changes
Nov 20, 2025
RohitRanjanMS
approved these changes
Nov 20, 2025
This was referenced Dec 3, 2025
Closed
This was referenced Dec 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For a long time, we've seen a decent number of errors coming from this code with the stack:
It's unclear how this is even possible given that the code here can seemingly never be null. But we're going to do some null-checks here to see if we can prevent these exceptions while we continue to investigate.Edit:
We figured out the underlying issue. In Functions if you have multiple input bindings we call BindAsync() all in parallel. This adds them to the underlying
_binderslist.But
list.Add(item)isn't thread-safe -- it can cause internal resizing, etc, which means that internally things can be in a bad state. Then later enumerating it can see null items when there should be none. If you use one of these null items, you get a NullRef.I was confused why the typical "add while enumerating" exceptions weren't being thrown, and it seemed like we would never even be in this state. But now it all makes sense with how Functions calls
BindAsync()in parallel.So the issue isn't "adding in one thread while enumerating in another" but it's "adding from multiple threads and then later enumerating". That explains why it never throws "collection was modified".