Skip to content

Conversation

@askpt
Copy link
Member

@askpt askpt commented Jan 23, 2026

Signed-off-by: André Silva 2493377+askpt@users.noreply.github.com

This PR

This pull request refactors the initialization and event handling logic in the InProcessResolver to simplify thread management and improve reliability. The main change is replacing the use of CountdownEvent and a background thread with a more modern TaskCompletionSource-based approach for signaling initialization completion.

Initialization and event handling improvements:

  • Replaced the use of CountdownEvent and manual thread management in Init() with a TaskCompletionSource<bool> and Task.Run, simplifying the initialization flow and reducing complexity.
  • Updated HandleEvents to accept a TaskCompletionSource<bool> instead of a CountdownEvent, and to signal initialization completion by calling TrySetResult(true) when the first event is received or on error. [1] [2] [3]

Notes

This should fix the flaky tests because we were not "signalling" correctly when the exception happens.

askpt added 2 commits January 23, 2026 13:54
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @askpt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the error handling and initialization process of the InProcessResolver by using TaskCompletionSource to manage asynchronous operations. This ensures that the Init() method completes gracefully, even in error scenarios, and simplifies the synchronization logic.

Highlights

  • Error Handling: The Init() method now handles error states by using a TaskCompletionSource to signal completion even when an exception occurs during the event handling, ensuring the provider is marked as 'ready' but in an error state.
  • Asynchronous Initialization: Replaced CountdownEvent with TaskCompletionSource for asynchronous initialization in Init(), simplifying the synchronization logic and improving readability.
  • Event Handling: Modified the HandleEvents method to use TaskCompletionSource to signal completion, allowing Init() to complete even if there are issues with the event stream.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the initialization logic in InProcessResolver to use TaskCompletionSource instead of CountdownEvent, which is a good modernization. It also aims to fix a hang in Init() by handling RpcException. My review identifies a critical flaw in the error handling strategy: other types of exceptions are not handled, which can still lead to Init() hanging. I've provided a comprehensive suggestion to make the error handling more robust, ensuring that all exceptions are managed correctly and that the provider initialization is resilient.

askpt added 2 commits January 23, 2026 14:14
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…) for improved test reliability

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
@askpt askpt marked this pull request as ready for review January 23, 2026 18:14
@askpt askpt requested review from a team as code owners January 23, 2026 18:14
@askpt askpt added the provider:flagd Issues related to provider flagd label Jan 26, 2026
{
// This is a transient error, so we signal that Init() can complete,
// but the provider is in an error state. We will then retry.
tcs.TrySetResult(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should set the state before or after we emitted the error event.
I am afraid that we might consider the provider to be in a non error state in the time from tcs.TrySetResult(true); to ProviderEvent?.Invoke(this, flagdEvent);, but I am also afraid to deadlock something (we had a roughly similar situation in the java flagd, which did result in a deadlock), because the event is not getting properly propagated

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point and thank you for your insight coming from Java experience. Fixed with 7489afc

…race condition

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider:flagd Issues related to provider flagd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants