Skip to content

fixed fixme and upgraded error handling #6595

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PranjaliBhardwaj
Copy link

@PranjaliBhardwaj PranjaliBhardwaj commented Aug 2, 2025

What type of PR is this?

/kind cleanup

What this PR does:

  1. Fixes code duplication issue in proxy upgrader
  2. Enhances error handling and resource cleanup
  3. Improves logging and documentation

Which issue(s) this PR fixes:

  • Improves error handling in proxy upgrader component
  • Enhances resource cleanup with proper defer usage
  • Fixes code duplication

Which issue(s) this PR fixes: #6594

@karmada-bot karmada-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/bug Categorizes issue or PR as related to a bug. labels Aug 2, 2025
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign chaunceyjiang for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot
Copy link
Collaborator

Welcome @PranjaliBhardwaj! It looks like this is your first PR to karmada-io/karmada 🎉

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.

Summary of Changes

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

I've addressed several areas in the pkg/util/proxy/upgrader.go file to enhance the stability and maintainability of the proxy upgrader component. My changes primarily focus on refining error handling to prevent unnecessary logging of expected connection terminations, ensuring robust resource cleanup through proper channel closure, and improving the clarity and correctness of a utility function by handling edge cases and adding documentation. These updates contribute to a more reliable and less noisy proxy operation.

Highlights

  • Improved Error Handling and Logging: I've introduced a new helper function, isExpectedConnectionError, to intelligently filter out common and expected connection closure errors (like "use of closed network connection" or "EOF") from being logged as critical errors. This significantly reduces log noise and helps focus on genuine issues.
  • Enhanced Resource Cleanup: I've refactored the tryUpgrade function to use defer close() for the writerComplete and readerComplete channels. This ensures that these channels are always properly closed when the goroutines exit, preventing potential resource leaks or deadlocks.
  • Code Duplication Fix and Clarity Improvements: I've updated the singleJoiningSlash utility function. This includes adding explicit handling for empty string inputs and providing clear comments for each case in the switch statement, making the function more robust and easier to understand. The old FIXME comment has also been removed.
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 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 or fill out our survey 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.

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.

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 2, 2025
@PranjaliBhardwaj
Copy link
Author

all changes are safe and tested.

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 improves error handling and resource management in the proxy upgrader. The changes are generally good, using defer for cleanup and centralizing error checking logic. I've identified a minor redundancy in the new isExpectedConnectionError function and suggested a simplification.

Comment on lines +361 to +387
func isExpectedConnectionError(err error) bool {
if err == nil {
return false
}

errorMsg := err.Error()
// Common expected connection errors
expectedErrors := []string{
"use of closed network connection",
"connection reset by peer",
"broken pipe",
"EOF",
}

for _, expected := range expectedErrors {
if strings.Contains(errorMsg, expected) {
return true
}
}

// Check for io.EOF specifically
if err == io.EOF {
return true
}

return false
}

Choose a reason for hiding this comment

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

medium

The check for io.EOF on lines 382-383 is redundant because the expectedErrors slice already contains "EOF". The loop on lines 375-379 will have already returned true if err is io.EOF (since io.EOF.Error() returns "EOF"), making the explicit check unreachable for that case. You can simplify the function by removing the redundant check.

func isExpectedConnectionError(err error) bool {
	if err == nil {
		return false
	}

	errorMsg := err.Error()
	// Common expected connection errors
	expectedErrors := []string{
		"use of closed network connection",
		"connection reset by peer",
		"broken pipe",
		"EOF",
	}

	for _, expected := range expectedErrors {
		if strings.Contains(errorMsg, expected) {
			return true
		}
	}

	return false
}

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.31%. Comparing base (b8f6874) to head (74cad97).

Files with missing lines Patch % Lines
pkg/util/proxy/upgrader.go 0.00% 52 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6595      +/-   ##
==========================================
- Coverage   45.34%   45.31%   -0.04%     
==========================================
  Files         687      687              
  Lines       56393    56436      +43     
==========================================
+ Hits        25571    25573       +2     
- Misses      29226    29268      +42     
+ Partials     1596     1595       -1     
Flag Coverage Δ
unittests 45.31% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RainbowMango
Copy link
Member

all changes are safe and tested.

@PranjaliBhardwaj Could you please clarify if this is a bug fix? I see you label this PR with kind/bug. If yes, can you elaborate it, like how to reproduce it?

@PranjaliBhardwaj
Copy link
Author

@RainbowMango my bad this pr aligns with documentation and code organization and not exactly a bug fix. i tried to make code more maintainable.

@RainbowMango RainbowMango removed the kind/bug Categorizes issue or PR as related to a bug. label Aug 4, 2025
@RainbowMango
Copy link
Member

No worries, I will put this into my queue and will take a look. In the meantime, could you address the failing lint checks?

Just out of curious, how do you find this?

@PranjaliBhardwaj
Copy link
Author

@RainbowMango Sure sir, actually I was very curious to contribute to Karmada and analyzing project since a long time, thought this would be a good first issue : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants