You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Barrier.RemoveParticipant can throw undocumented BarrierPostPhaseException #125565
In System.Threading.Barrier method RemoveParticipants can throw a BarrierPostPhaseException however the documentation for that method only lists ObjectDisposedException and InvalidOperationException. The unit test below exhibits the issue by failing via an Assert.Inconclusive (which I chose since this may be a documentation issue rather than a code issue).
The source of the issue seems to be that both SignalAndWait and RemoveParticipant call FinishPhase and the latter may trigger a BPPE is the post-phase action throws.
[TestMethod]publicvoidBarrier_RemoveParticipant_ThrowsBPPE_WhenPostPhaseActionThrows(){conststringmsg="post-phase failure";varbarrier=newBarrier(2, _ =>thrownewInvalidOperationException(msg));vart=Task.Run(()=>{barrier.SignalAndWait();// signal and wait for phase to complete});// Give task time to signalThread.Sleep(50);// Now remove the second participant — this should trigger FinishPhase,// which runs the post-phase action, which throws, resulting in BPPEtry{barrier.RemoveParticipant();Assert.Fail("Expected BarrierPostPhaseException was not thrown; "+"behavior may have changed since test was written.");}catch(BarrierPostPhaseExceptionbppe){Assert.IsInstanceOfType<InvalidOperationException>(bppe.InnerException);Assert.AreEqual(msg,bppe.InnerException!.Message);Assert.Inconclusive("This is undocumented behavior!");}finally{// t.Wait(); // will throwbarrier.Dispose();}}
Activity
dotnet-policy-service commentedon Mar 15, 2026
Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.