Skip to content

Cache the DSN resolution result to avoid repeated lookup#482

Merged
AayushTyagi1 merged 1 commit intomainfrom
private-link-issue
Mar 24, 2026
Merged

Cache the DSN resolution result to avoid repeated lookup#482
AayushTyagi1 merged 1 commit intomainfrom
private-link-issue

Conversation

@AayushTyagi1
Copy link
Copy Markdown
Collaborator

Describe the problem this PR is solving

Short description of the changes

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AayushTyagi1, 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 improves the efficiency and reliability of network connections by introducing a robust DNS resolution caching system. It intelligently caches DNS SRV lookup results, including handling for private endpoints, to minimize redundant network calls. Additionally, it bolsters the application's stability by adding critical input validation for connection parameters and ensuring proper cache invalidation upon connection removal.

Highlights

  • DNS Resolution Caching: Implemented a caching mechanism for DNS Service (SRV) record lookups in NSLookup.ts to reduce repeated network requests and improve performance. The cache has a 5-minute TTL.
  • Private Endpoint Handling: The DNS caching logic now intelligently handles private endpoints by skipping SRV lookups for URLs identified as private or for those that previously resulted in an ENOTFOUND error, caching this information to prevent future failed attempts.
  • Robust Connection URL Handling: Enhanced CouchbaseRestAPI.ts to include explicit checks for valid server URLs returned by getServerURL, and added comprehensive input validation for connection URLs and usernames in connections.ts during connection setup and testing.
  • DNS Cache Invalidation: Added functionality to clear specific DNS cache entries when a connection is removed, ensuring that stale or incorrect DNS information is not retained for deleted connections.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 a valuable caching layer for DNS resolution to improve performance and adds several input validations to increase robustness. However, it also introduces a critical security vulnerability: connection URLs, which can contain embedded credentials, are logged in error or debug messages, potentially leading to sensitive information leakage in the VS Code output channel. Furthermore, there are high-severity issues including a bug in the new caching logic causing unnecessary network lookups, and an issue with the SDK Doctor utility call leading to incorrect connection diagnostics. Addressing these concerns, particularly sanitizing URLs before logging, is crucial for a solid and reliable improvement.

Comment thread src/util/apis/NSLookup.ts Outdated
Comment on lines +62 to +72
if (cachedEntry && isCacheValid(cachedEntry)) {
if (cachedEntry.isPrivateEndpoint) {
// For known private endpoints, skip SRV lookup entirely
logger.debug(`Using cached result for private endpoint: ${url}`);
return [];
}
if (cachedEntry.servers.length > 0) {
logger.debug(`Using cached DNS SRV result for: ${url}`);
return cachedEntry.servers;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current cache-checking logic has a flaw. If a DNS SRV lookup for a non-private endpoint successfully returns an empty list of servers, this result is cached. However, on subsequent calls, the condition if (cachedEntry.servers.length > 0) will be false, causing the code to fall through and perform the DNS lookup again. This defeats the purpose of caching for this scenario.

The logic can be simplified to correctly handle all cached cases, including empty server lists for non-private endpoints. By returning cachedEntry.servers directly when a valid cache entry is found, you ensure that all successful lookups (even those with no results) are properly cached and served.

    if (cachedEntry && isCacheValid(cachedEntry)) {
        logger.debug(`Using cached DNS result for: ${url}`);
        return cachedEntry.servers;
    }

Comment thread src/util/apis/CouchbaseRestAPI.ts Outdated
Comment thread src/util/apis/CouchbaseRestAPI.ts Outdated
Comment thread src/util/apis/CouchbaseRestAPI.ts Outdated
Comment thread src/util/apis/CouchbaseRestAPI.ts Outdated
Comment thread src/util/apis/CouchbaseRestAPI.ts Outdated
Comment thread src/util/apis/NSLookup.ts Outdated
Comment thread src/util/apis/NSLookup.ts Outdated
VirajAgarwal1
VirajAgarwal1 previously approved these changes Jan 30, 2026
@AayushTyagi1
Copy link
Copy Markdown
Collaborator Author

This I will put as a part of MCP release

@AayushTyagi1 AayushTyagi1 dismissed VirajAgarwal1’s stale review March 16, 2026 10:39

It was emergency review for a customer but not being reviewed properly. Need to get it reviewed.

@AayushTyagi1 AayushTyagi1 requested review from VirajAgarwal1 and removed request for VirajAgarwal1 March 16, 2026 12:32
@AayushTyagi1 AayushTyagi1 merged commit 4c6158f into main Mar 24, 2026
3 of 6 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.

3 participants