libzlibz opened a new issue, #209:
URL: https://github.com/apache/pulsar-dotpulsar/issues/209

   ### Description
   
   SendChannel.Completion causes the producer to become Faulted
   
   
   ### Reproduction Steps
   
   // ---Thread1---
   // while(true) {
   // a:producer.Send a batch of data
   // a:await producer.SendChannel.Completion
   //  a:await _sendQueue.WaitForEmpty
   //      a:tcs = new TaskCompletionSource<object>();
   //      a:_queueEmptyTcs.Add(tcs);
   //      a:await tcs.Task
   // 
   //                             ---Thread2---
   //                             SubProducer::ProcessReceipt
   //                                 _sendQueue.Dequeue();
   //                                     if (_queue.Count == 0)
   //                                         NotifyQueueEmptyAwaiters();
   //                                             1:foreach (var tcs in 
_queueEmptyTcs)
   //                                             1:    tcs.TrySetResult(0);
   //
   // Return to running the statement following: await tcs.Task
   // b:producer.Send
   // b:await producer.SendChannel.Completion
   //      b:_queueEmptyTcs.Add(tcs);(Modified _queueEmptyTcs)
   //      b:await tcs.Task
   // 
   //                             ---Thread2-------------------------
   //                                             2:foreach (var tcs in 
_queueEmptyTcs) //When running within foreach, _queueEmptyTcs has been modified 
and there is an issue at this time
   //                                              Throwing exception: 
Collection was modified; enumeration operation may not execute
   //                                              producer set to Faulted
   // }
   
   // TrySetResult will notify await tcs.Task completed, then Thread1 continues 
to run, and then b: _queueEmptyTcs.Add(tcs) modified _queueEmptyTcs, causing 
foreach issue in Thread2
   // Additionally, it was found that a:await tcs.Task was return after 
1:tcs.TrySetResult(0), The code behind the (await tcs.Task) runs in Thread2, so 
every time you enter NotifyQueueEmptyAwaiters, there will always be a problem
   // Do not add: lock (_queue) to void NotifyQueueEmptyAwaiters(), After 
testing, on the same thread, it was found that it will not lock, but errors 
will still be reported
   
   
   
   ### Expected behavior
   
   Normal and stable production data
   
   ### Actual behavior
   
   producer to become Faulted
   
   ### Regression?
   
   _No response_
   
   ### Known Workarounds
   
   _No response_
   
   ### Configuration
   
   _No response_
   
   ### Other information
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to