[CSHARP-1956] BulkWrite freezes upon writing 0 records Created: 30/Mar/17 Updated: 17/Oct/17 Resolved: 17/Oct/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.4.3 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Matthew Czarnek | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I'm finding that when I call collection_name.BulkWrite and pass in a List<WriteModel<>> that has 0 elements in it, BulkWrite will freeze and seems stuck in an infinite loop or something. Easy enough to fix but considering I was multi-threading this and it was rare for this to occur.. it was a pain to debug. To be far, it throws an exception I was catching and ignoring Here is a snippet of code that was causing the crash if it helps:
|
| Comments |
| Comment by Robert Stam [ 06/Apr/17 ] | ||||||
|
I don't know the data type of your _cacheRecords variable, but BulkWrite receives it as an IEnumerable<WriteModel<TDocument>>. Internally BulkWrite has to enumerate the requests variable, which results in indirectly calling GetEnumerator to get an enumerator, and then calling MoveNext to determine if there are any more items in the sequence. It is possible that the call to MoveNext is the one that is blocking for hours. Also, there is an open issue regarding that BulkWrite enumerates the requests sequence more than once. Depending on how that sequence is implemented, the multiple enumeration may or may not result in a problem. See CSHARP-1378. | ||||||
| Comment by Robert Stam [ 06/Apr/17 ] | ||||||
|
It is considered an error to call BulkWrite with an empty list of requests, and BulkWrite will throw an exception if it is called with an empty list. Consider the following test:
It throws the following exception immediately:
|