Skip to content

Commit

Permalink
Clear async-context inside RRLB health checking (#2220)
Browse files Browse the repository at this point in the history
Motivation:
Health checking is an indefinite process (for as long as the host is present), and relying on async-context can lead to misbehavior with code storing stuff in it.

Modification:
Upon subscribing for the health-check process, we clear async-context.

Result:
No state maintained in async-context for the lifetime of health-checking.
  • Loading branch information
tkountis authored May 20, 2022
1 parent 0f0f86e commit c0b80c0
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.servicetalk.concurrent.PublisherSource.Subscriber;
import io.servicetalk.concurrent.PublisherSource.Subscription;
import io.servicetalk.concurrent.api.AsyncCloseable;
import io.servicetalk.concurrent.api.AsyncContext;
import io.servicetalk.concurrent.api.Completable;
import io.servicetalk.concurrent.api.CompositeCloseable;
import io.servicetalk.concurrent.api.Executor;
Expand Down Expand Up @@ -777,6 +778,8 @@ public void schedule(final Throwable originalCause) {
host.healthCheckConfig.healthCheckInterval,
host.healthCheckConfig.executor)
.apply(0, originalCause)
// Remove any state from async context
.beforeOnSubscribe(__ -> AsyncContext.clear())
.concat(connectionFactory.newConnection(host.address, null, null)
// There is no risk for StackOverflowError because result of each connection
// attempt will be invoked on IoExecutor as a new task.
Expand Down

0 comments on commit c0b80c0

Please sign in to comment.