Skip to content

use cancel token instead of broadcast channel#25

Open
akundaz wants to merge 5 commits intomainfrom
ak-use-cancel-token
Open

use cancel token instead of broadcast channel#25
akundaz wants to merge 5 commits intomainfrom
ak-use-cancel-token

Conversation

@akundaz
Copy link
Contributor

@akundaz akundaz commented Feb 24, 2026

Extremely minimal change. Only changes the channel usage so a cancel token is used instead

@akundaz akundaz self-assigned this Feb 24, 2026
}
};

let circuit_breaker = CircuitBreaker::new(circuit_breaker_config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue:

this change makes circuit-breaker being dropped each time it detects backend unhealthy, which breaks its logic around threshold_healtlhy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part of the logic seems broken to you? The circuit breaker restarts along with the proxies so it seemed fine to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not fine

}

_ = canceller.cancelled() => {
_ = reset_signal.cancelled() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue:

the whole point of circuit-breaker is that it it's initialised once and runs for the whole duration of the process observing the status of the backend, applying threshold for healthy/unhealthy, and resetting the proxies when necessary.

this line effectively makes it self-terminate each time it detects backend unhealthy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it restarts when it spins up new backends. This seems functionally equivalent to me and it makes sense that the lifetime of the circuit breaker is tied to the lifetime of the services it's managing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

circuit-breaker can not properly apply "healthy" threshold if it's being restarted together with the proxies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate? I could make the circuit break hold onto an Arc<Mutex<Option>> instead but I'd rather avoid adding mutability. Why can it not apply the healthy threshold if it's restarted with the proxies?

Copy link
Member

@0x416e746f6e 0x416e746f6e Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after circuit-breaker marks backend as unhealthy it is supposed to count how many probes succeed consecutively and only once the threshold is reached it should flag backend as healthy again.

if it is restarted together with proxies, then it immediately considers the backend healthy (as if healthy threshold is always 0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only issue? It sounds like I should just initialize the circuit breaker with curr_status = Status::Unhealthy upon restarts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.d.k. that's the one that clearly pops up.

re-initialising the circuit-breaker from its past incarnation sounds way too artificial. what is the added value vs. the pattern that already exists: namely persistent circuit-breaker with a channel to send reset signals over?

the point of ditching the channel in favour of cancellation signal was to simplify things. now they don't look any simpler, and not even complex - but complicated instead.

Base automatically changed from fix/lagging-resetter-channel to main March 5, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants