Skip to content

feat(ofrep): add close to OFREP core #1486

Merged
toddbaert merged 3 commits intomainfrom
fix/ofrep-shutdown-timeout-cleanup
Mar 27, 2026
Merged

feat(ofrep): add close to OFREP core #1486
toddbaert merged 3 commits intomainfrom
fix/ofrep-shutdown-timeout-cleanup

Conversation

@beeme1mr
Copy link
Copy Markdown
Member

@beeme1mr beeme1mr commented Mar 9, 2026

This PR

This pull request focuses on resource management, graceful shutdown, and test coverage. The most significant changes ensure that in-flight requests can be aborted, timers are properly cleaned up, and the provider can be safely closed, preventing further evaluations.

Resource management and graceful shutdown:

  • Added a close() method to the OFREPApi class that aborts any in-flight requests and prevents further usage after shutdown. The doFetchRequest method now checks for shutdown and rejects requests if the provider has been closed. (libs/shared/ofrep-core/src/lib/api/ofrep-api.ts) [1] [2]
  • Updated the OFREPProvider and OFREPWebProvider classes to call the API's close() method in their onClose() implementations, ensuring proper resource release. (libs/providers/ofrep/src/lib/ofrep-provider.ts, libs/providers/ofrep-web/src/lib/ofrep-web-provider.ts) [1] [2]

Bug fixes:

  • Fixed a missing return statement in the isomorphicFetch function to ensure correct fetch implementation selection. (libs/shared/ofrep-core/src/lib/api/ofrep-api.ts)

Related Issues

Fixes #1479

Follow-up Tasks

We'll need to release core prior to the other libraries and update the minimum dependency version in OFREP and OFREP Web.

How to test

  • Added tests to verify that timers are cleaned up after requests, that in-flight requests are aborted on close, and that no pending timers remain after completion. (libs/shared/ofrep-core/src/lib/api/ofrep-api.spec.ts)
  • Added tests to ensure the provider's onClose method can be called and that evaluations are rejected after closure. (libs/providers/ofrep/src/lib/ofrep-provider.spec.ts)

@beeme1mr beeme1mr requested review from a team as code owners March 9, 2026 16:00
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly enhances the robustness and resource management of the OFREP providers by introducing a comprehensive shutdown mechanism. It ensures that all in-flight requests are gracefully terminated and resources are properly released when a provider is closed, preventing potential memory leaks or unexpected behavior. This change improves the overall stability and reliability of the OpenFeature OFREP integration.

Highlights

  • Graceful Shutdown: Implemented a close() method in OFREPApi to abort in-flight requests and prevent further evaluations, ensuring proper resource release.
  • Provider Integration: Updated OFREPProvider and OFREPWebProvider to utilize the new OFREPApi.close() method within their onClose() implementations.
  • Bug Fix: Corrected a missing return statement in the isomorphicFetch function for accurate fetch implementation selection.
  • Dependency Update: Upgraded the @openfeature/ofrep-core dependency to version 2.1.0 in both provider packages.
  • Enhanced Test Coverage: Added comprehensive tests for timer cleanup, in-flight request abortion, and post-closure evaluation rejection.
Changelog
  • libs/providers/ofrep-web/package.json
    • Updated @openfeature/ofrep-core dependency from ^2.0.0 to ^2.1.0.
  • libs/providers/ofrep-web/src/lib/ofrep-web-provider.ts
    • Added a call to this._ofrepAPI.close() within the onClose() method to ensure proper resource cleanup.
  • libs/providers/ofrep/package.json
    • Updated @openfeature/ofrep-core dependency from ^2.0.0 to ^2.1.0.
  • libs/providers/ofrep/src/lib/ofrep-provider.spec.ts
    • Added a test to verify that the onClose method is defined and can be called without throwing an error.
    • Added a test to confirm that evaluations are rejected after the onClose method has been invoked.
  • libs/providers/ofrep/src/lib/ofrep-provider.ts
    • Implemented the onClose() method to delegate the closing operation to the ofrepApi instance.
  • libs/shared/ofrep-core/src/lib/api/ofrep-api.spec.ts
    • Added tests to ensure clearTimeout is called after both successful and failed requests, verifying proper timer cleanup.
    • Included a test to confirm no pending timers remain after a request completes.
    • Added a test to verify that in-flight requests are aborted when the close() method is called.
  • libs/shared/ofrep-core/src/lib/api/ofrep-api.ts
    • Corrected a missing return statement in the isomorphicFetch function for the self context.
    • Introduced a _shutdownController (an AbortController) to manage the shutdown state of the API.
    • Added a public close() method that triggers the _shutdownController to abort any pending operations.
    • Modified doFetchRequest to check if the provider is closed, rejecting new requests if it is.
    • Integrated the _shutdownController's signal with individual request controllers to allow global abortion.
    • Ensured clearTimeout is called and the shutdown event listener is removed in a finally block for robust resource management.
Activity
  • The author, beeme1mr, initiated the pull request to add proper shutdown cleanup to OFREP.
  • Tests were added to verify timer cleanup after requests, abortion of in-flight requests on close, and the absence of pending timers.
  • Tests were also added to ensure the provider's onClose method functions correctly and that evaluations are rejected after closure.
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
Copy Markdown
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 introduces graceful shutdown capabilities to the OFREP providers. A close() method has been added to OFREPApi which aborts in-flight requests using an AbortController. The OFREPProvider and OFREPWebProvider are updated to call this new method on close. The changes also include a bugfix for a missing return statement and comprehensive tests for the new shutdown logic. My review focuses on the implementation of the shutdown mechanism. I've found one minor opportunity for code simplification to improve readability.

Comment thread libs/shared/ofrep-core/src/lib/api/ofrep-api.ts Outdated
Copy link
Copy Markdown
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

This looks good to me!

@beeme1mr beeme1mr changed the title feature(ofrep): add proper shutdown cleanup to OFREP feat(ofrep): add proper shutdown cleanup to OFREP Mar 9, 2026
@beeme1mr beeme1mr requested a review from toddbaert March 9, 2026 22:04
Comment thread libs/providers/ofrep-web/src/lib/ofrep-web-provider.ts
Copy link
Copy Markdown
Member

@jonathannorris jonathannorris left a comment

Choose a reason for hiding this comment

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

Looks good, I would probably change the PR title to fix(ofrep):

@beeme1mr
Copy link
Copy Markdown
Member Author

Looks good, I would probably change the PR title to fix(ofrep):

Maybe I should split this into two separate PRs because the fix adds a new method to core and we'll need to bump the min version in the consuming providers. FYI @toddbaert

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
@toddbaert toddbaert force-pushed the fix/ofrep-shutdown-timeout-cleanup branch from e9751ca to ce699a0 Compare March 27, 2026 18:01
@toddbaert toddbaert changed the title feat(ofrep): add proper shutdown cleanup to OFREP fix(ofrep): add proper shutdown cleanup to OFREP Mar 27, 2026
@toddbaert toddbaert changed the title fix(ofrep): add proper shutdown cleanup to OFREP feat(ofrep): add close to OFREP core Mar 27, 2026
@toddbaert
Copy link
Copy Markdown
Member

Looks good, I would probably change the PR title to fix(ofrep):

Maybe I should split this into two separate PRs because the fix adds a new method to core and we'll need to bump the min version in the consuming providers. FYI @toddbaert

I'll just merge this as is, but make separate fixes to absorb this in the providers, and update the min version + release.

@toddbaert toddbaert merged commit 44ab1f7 into main Mar 27, 2026
9 checks passed
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.

[OFREP] Hanging timeout causes runtime issues

5 participants