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

Disable HTTP cache option with env var CDXGEN_NO_CACHE #1681

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

emcfins
Copy link
Contributor

@emcfins emcfins commented Mar 12, 2025

Resolves #1620

In my builds, the cache option was causing problems creating an SBOM, at times abruptly stopping without any error or generated SBOM.

We were able to track it down to using the cache option with the got HTTP agent. Without it, the SBOMs were able to be generated. This PR enables the toggling of using the cache option, with the default of using the cache.

We attempted to get around the issue with setting the environment variable CDXGEN_SECURE_MODE but that did not resolve the issue.

emcfins added 3 commits March 12, 2025 12:44
Signed-off-by: Erin McGill <[email protected]>
Signed-off-by: Erin McGill <[email protected]>
Add the ability to toggle off setting the `cache` option for the HTTP agent.

Signed-off-by: Erin McGill <[email protected]>
@emcfins emcfins requested a review from prabhu as a code owner March 12, 2025 16:49
Copy link

@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.

Hello @emcfins, 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!

Summary of Changes

This pull request addresses issue #1620 by introducing an environment variable, CDXGEN_NO_CACHE, to disable the HTTP cache option. The author found that the cache was causing problems in their builds, leading to abrupt stops during SBOM generation. This PR modifies the utils.js file to check for the presence and value of the CDXGEN_NO_CACHE environment variable. If set to true or 1, the cache option is disabled. Additionally, the documentation (ENV.md) and the fine-tuning data (env.jsonl) have been updated to reflect this new environment variable.

Highlights

  • New Feature: Introduces CDXGEN_NO_CACHE environment variable to disable HTTP cache.
  • Bug Fix: Addresses issues where the cache was causing problems during SBOM generation.
  • Documentation: Updates documentation and fine-tuning data to reflect the new environment variable.

Changelog

  • contrib/fine-tuning/cdxgen-docs/env.jsonl
    • Added a new entry to the fine-tuning data to explain how to disable the HTTP cache using the CDXGEN_NO_CACHE environment variable. The new entry is added as line 73.
  • docs/ENV.md
    • Added a new row to the environment variables table to document the CDXGEN_NO_CACHE variable and its usage. The new row is inserted as line 16.
  • lib/helpers/utils.js
    • Introduced a new function isCacheDisabled to check the value of the CDXGEN_NO_CACHE environment variable. The new function is added between lines 616 and 624.
    • Modified the cdxgenAgent to conditionally use the gotHttpCache based on the result of isCacheDisabled. The cache property is modified on line 629.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


Did you know?

HTTP caching can significantly improve website loading times by storing frequently accessed resources closer to the user.

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

@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 a new environment variable CDXGEN_NO_CACHE to disable the HTTP cache option. The changes look good and address the reported issue. Here are some minor suggestions.

Merge Readiness

The pull request is ready to be merged after addressing the review comments. I am unable to directly approve this pull request, and recommend that users have others review and approve this code before merging.

@@ -614,12 +614,19 @@ export function isPackageManagerAllowed(name, conflictingManagers, options) {
// HTTP cache
const gotHttpCache = new Map();

function isCacheDisabled() {
const noCache = process.env.CDXGEN_NO_CACHE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use the below style of checking in the codebase. Shall we make this consistent?

["true", "1"].includes(process.env.CDXGEN_NO_CACHE)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the repo owner, it's up to you.

I made the changes based on the gemini-code-assist bot.

Choose a reason for hiding this comment

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

The suggested approach by @prabhu to use ["true", "1"].includes(process.env.CDXGEN_NO_CACHE) is a common pattern in JavaScript for boolean environment variables. It's more explicit than a simple truthy/falsy check and aligns well with the project's goal of clarity. I'd recommend adopting it for consistency.

Suggested change
const noCache = process.env.CDXGEN_NO_CACHE;
function isCacheDisabled() {
const noCache = ["true", "1"].includes(process.env.CDXGEN_NO_CACHE);

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.

No SBOM generated when FETCH_LICENSE=true is set
2 participants