Skip to content

Conversation

@nstapelbroek
Copy link

Hi friends,

All download methods (DownloadFile, DownloadTranslation, and mt.Downloader.File) were returning io.Reader instead of io.ReadCloser, even though the underlying Client.Get() returns io.ReadCloser. This prevented callers from closing the HTTP response body, causing connection leaks.

I've updated the methods and their signatures. SDK clients should now be able to prevent memory leaks 🥳

allowing our sdk clients to prevent memory leaks
Copilot AI review requested due to automatic review settings January 20, 2026 13:32
@gemini-code-assist
Copy link

Summary of Changes

Hello @nstapelbroek, 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 addresses a critical resource management issue by modifying the return types of several download-related functions. Previously, these functions returned io.Reader, which did not provide a mechanism for callers to close the underlying HTTP response bodies, leading to connection leaks. By changing the return type to io.ReadCloser, SDK clients can now explicitly close these resources, ensuring proper cleanup and preventing resource exhaustion.

Highlights

  • Return Type Change: All download methods (DownloadFile, DownloadTranslation, and mt.Downloader.File) now return io.ReadCloser instead of io.Reader.
  • Resource Management: This change allows callers to properly close the underlying HTTP response body, preventing potential connection and memory leaks.
  • Interface and Implementation Updates: The APIClient interface and the httpDownloader implementation have been updated to reflect the new return type.

🧠 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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates download-related APIs to return io.ReadCloser instead of io.Reader, allowing callers to properly close HTTP response bodies and avoid connection leaks.

Changes:

  • Change HttpAPIClient.DownloadFile to return io.ReadCloser and propagate the underlying Client.Get body directly.
  • Change HttpAPIClient.DownloadTranslation to return io.ReadCloser.
  • Update the APIClient and mt.Downloader interfaces (and httpDownloader.File implementation) to use io.ReadCloser for downloaded content.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
client_download_translation.go Adjusts DownloadTranslation return type to io.ReadCloser to expose a closable response body.
client_download_file.go Adjusts DownloadFile return type to io.ReadCloser to expose a closable response body.
client.go Updates APIClient interface method signatures to match the new io.ReadCloser return types.
api/mt/downloader.go Updates the Downloader interface and httpDownloader.File implementation to return io.ReadCloser for MT file downloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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 correctly addresses a potential connection leak by changing the return type of download methods from io.Reader to io.ReadCloser. This allows callers to properly close the underlying HTTP response body. The changes are consistent across all modified interfaces and implementations. My review includes several suggestions to improve the documentation for these methods, making it explicit that the caller is responsible for closing the returned io.ReadCloser. This will improve the clarity of the API and help prevent future misuse.

type Downloader interface {
File(accountUID AccountUID, fileUID FileUID,
mtUID MtUID, localeID string) (io.Reader, error)
mtUID MtUID, localeID string) (io.ReadCloser, error)

Choose a reason for hiding this comment

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

medium

With the return type changed to io.ReadCloser, it's crucial to document that the caller is responsible for closing it. Please add a comment to the method signature to make this contract explicit and prevent resource leaks. For example: // File downloads a file. The caller must close the returned ReadCloser.

// File downloads file
func (d httpDownloader) File(accountUID AccountUID, fileUID FileUID,
mtUID MtUID, localeID string) (io.Reader, error) {
mtUID MtUID, localeID string) (io.ReadCloser, error) {

Choose a reason for hiding this comment

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

medium

The comment for this function is // File downloads file. Please update it to be more descriptive and to mention that the caller is responsible for closing the returned io.ReadCloser.

Comment on lines +34 to +35
DownloadFile(projectID string, uri string) (io.ReadCloser, error)
DownloadTranslation(projectID string, localeID string, request FileDownloadRequest) (io.ReadCloser, error)

Choose a reason for hiding this comment

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

medium

To make the API contract clearer and prevent resource leaks, please add comments to DownloadFile and DownloadTranslation indicating that the caller is responsible for closing the returned io.ReadCloser.

projectID string,
uri string,
) (io.Reader, error) {
) (io.ReadCloser, error) {

Choose a reason for hiding this comment

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

medium

Please update the function's documentation (// DownloadFile downloads original file from project.) to mention that the caller must close the returned io.ReadCloser.

localeID string,
request FileDownloadRequest,
) (io.Reader, error) {
) (io.ReadCloser, error) {

Choose a reason for hiding this comment

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

medium

Please update this function's documentation to clarify that the caller is responsible for closing the returned io.ReadCloser.

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.

1 participant