@@ -19,7 +19,7 @@ internal sealed class CircuitStateController<T> : IDisposable
19
19
private DateTimeOffset _blockedUntil ;
20
20
private CircuitState _circuitState = CircuitState . Closed ;
21
21
private Outcome < object > ? _lastOutcome ;
22
- private BrokenCircuitException ? _breakingException ;
22
+ private BrokenCircuitException _breakingException = new ( ) ;
23
23
private bool _disposed ;
24
24
25
25
public CircuitStateController (
@@ -134,8 +134,8 @@ public ValueTask CloseCircuitAsync(ResilienceContext context)
134
134
135
135
exception = _circuitState switch
136
136
{
137
- CircuitState . Open => GetBreakingException_NeedsLock ( ) ,
138
- CircuitState . HalfOpen when isHalfOpen is false => GetBreakingException_NeedsLock ( ) ,
137
+ CircuitState . Open => _breakingException ,
138
+ CircuitState . HalfOpen when isHalfOpen is false => _breakingException ,
139
139
CircuitState . Isolated => new IsolatedCircuitException ( ) ,
140
140
_ => null
141
141
} ;
@@ -261,7 +261,6 @@ private void CloseCircuit_NeedsLock(Outcome<T> outcome, bool manual, ResilienceC
261
261
262
262
_blockedUntil = DateTimeOffset . MinValue ;
263
263
_lastOutcome = null ;
264
- _breakingException = null ;
265
264
266
265
CircuitState priorState = _circuitState ;
267
266
_circuitState = CircuitState . Closed ;
@@ -294,7 +293,6 @@ private bool PermitHalfOpenCircuitTest_NeedsLock()
294
293
private void SetLastHandledOutcome_NeedsLock < TResult > ( Outcome < TResult > outcome )
295
294
{
296
295
_lastOutcome = outcome . AsOutcome ( ) ;
297
- _breakingException = null ;
298
296
299
297
if ( outcome . Exception is Exception exception )
300
298
{
@@ -304,12 +302,8 @@ private void SetLastHandledOutcome_NeedsLock<TResult>(Outcome<TResult> outcome)
304
302
{
305
303
_breakingException = new BrokenCircuitException < TResult > ( BrokenCircuitException . DefaultMessage , result ! ) ;
306
304
}
307
-
308
- _breakingException ? . TrySetStackTrace ( ) ;
309
305
}
310
306
311
- private BrokenCircuitException GetBreakingException_NeedsLock ( ) => _breakingException ?? new BrokenCircuitException ( ) ;
312
-
313
307
private void OpenCircuit_NeedsLock ( Outcome < T > outcome , bool manual , ResilienceContext context , out Task ? scheduledTask )
314
308
{
315
309
OpenCircuitFor_NeedsLock ( outcome , _breakDuration , manual , context , out scheduledTask ) ;
0 commit comments