Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retire FakeFiber #1238

Merged
merged 1 commit into from
Sep 27, 2023
Merged

Retire FakeFiber #1238

merged 1 commit into from
Sep 27, 2023

Conversation

biochimia
Copy link
Contributor

FakeFiber was used by KafkaConsumer to manage:

  1. the consumerActor fiber, processing requests (including polls);
  2. the pollScheduler fiber, scheduling poll requests (subject to backpressure);
  3. a fiber combining the above two fibers.

Compared to a regular fiber, FakeFiber offered a method to combine two fibers by racing them one against the other. The semantics were similar to the race method for effects, but operating at the fiber level.

In KafkaConsumer, FakeFiber was used with cancellation effects that returned immediately (i.e., fiber.cancel.start.void). In addition the fiber outcome was relayed to KafkaConsumer.awaitTermination.

With this change FakeFiber is replaced with an Async[F].race of the underlying effects. This is managed in the new method startBackgroundConsumer, which builds upon effects assembled by runConsumerActor and runPollScheduler. These effects are unwrapped from the previous fibers.

As before, cancellation of the consumer effect is only waited on in awaitTermination, where any errors are propagated.

Compared to the original behaviour of FakeFiber.combine, starting with cats-effect 3.5.0, cancellation of one of the consumer effects will lead to cancellation of both, as per changes introduced with typelevel/cats-effect#3453. I'm not sure how cancelation would come into play here, but the behaviour change looks appropriate: without one of the racing fibers KafkaConsumer would not be functional (no polls scheduled, or no requests/polls processed).

FakeFiber was used by KafkaConsumer to manage:

1. the consumerActor fiber, processing requests (including polls);
2. the pollScheduler fiber, scheduling poll requests (subject to
   backpressure);
3. a fiber combining the above two fibers.

Compared to a regular fiber, FakeFiber offered a method to combine two
fibers by racing them one against the other. The semantics were similar
to the race method for effects, but operating at the fiber level.

In KafkaConsumer, FakeFiber was used with cancellation effects that
returned immediately (i.e., fiber.cancel.start.void). In addition the
fiber outcome was relayed to KafkaConsumer.awaitTermination.

With this change FakeFiber is replaced with an Async[F].race of the
underlying effects. This is managed in the new method
startBackgroundConsumer, which builds upon effects assembled by
runConsumerActor and runPollScheduler. These effects are unwrapped from
the previous fibers.

As before, cancellation of the consumer effect is only waited on in
awaitTermination, where any errors are propagated.

Compared to the original behaviour of FakeFiber.combine, starting with
cats-effect 3.5.0, cancellation of one of the consumer effects will lead
to cancellation of both, as per changes introduced with
typelevel/cats-effect#3453. I'm not sure how
cancelation would come into play here, but the behaviour change looks
appropriate: without one of the racing fibers KafkaConsumer would not be
functional (no polls scheduled, or no requests/polls processed).
@biochimia
Copy link
Contributor Author

As motivation for doing this, I'm running down different code paths trying to understand how partitions may get "lost", in relation to #1230. To be clear, I have not identified any issue with FakeFiber that would relate to that.

I do note that FakeFiber was introduced to support the upgrade to cats-effect 3.x, and that its behaviour seems to be well supported by racing the effects directly, instead. With this change the goal is to remove a little bit of legacy and hopefully reduce cognitive load as well.

Copy link
Contributor

@aartigao aartigao left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏽

@aartigao aartigao merged commit fa08ba9 into fd4s:series/3.x Sep 27, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants