Skip to content

Conversation

@Wangzy455
Copy link

@Wangzy455 Wangzy455 commented Sep 26, 2025

What this PR does:
for #879

Which issue(s) this PR fixes:
fix some issue about getty

@github-actions github-actions bot added bug Something isn't working coding remoting labels Sep 26, 2025
@AlexStocks AlexStocks requested a review from Copilot September 27, 2025 05:51
Copy link
Contributor

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 fixes bugs in the getty remoting layer by implementing proper session cleanup, resource management, and reconnection functionality with exponential backoff.

  • Adds proper session resource cleanup when sessions close or encounter errors
  • Implements proper cleanup of message futures to prevent memory leaks
  • Introduces reconnection logic with exponential backoff strategy for improved client reliability

Reviewed Changes

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

File Description
pkg/remoting/getty/session_manager.go Adds cleanupSessionResources method to properly clean up session attributes
pkg/remoting/getty/listener.go Adds cleanupSession calls in OnError and OnClose handlers
pkg/remoting/getty/getty_remoting.go Fixes memory leak by properly deleting processed message futures
pkg/remoting/getty/getty_client.go Adds reconnection logic with exponential backoff functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 113 to 134
func (client *GettyRemotingClient) reconnectWithBackoff(session getty.Session, maxRetries int) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := backoff.Config{
MinBackoff: 1 * time.Second,
MaxBackoff: 60 * time.Second,
MaxRetries: maxRetries,
}
backoffInstance := backoff.New(ctx, cfg)

log.Infof("Starting reconnection attempts with backoff for session: %s", session.Stat())

for backoffInstance.Ongoing() {
backoffInstance.Wait()

log.Infof("Reconnection attempt %d for session: %s", backoffInstance.NumRetries(), session.Stat())
}

if err := backoffInstance.Err(); err != nil {
log.Errorf("Reconnection failed after %d attempts: %v", backoffInstance.NumRetries(), err)
}
}
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The reconnectWithBackoff method performs only logging but doesn't actually attempt to reconnect. The loop should include actual reconnection logic instead of just waiting and logging.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

done

Comment on lines 149 to 152
func (g *gettyClientHandler) cleanupSession(session getty.Session) {
session.RemoveAttribute(heartBeatRetryTimesKey)
log.Debugf("Cleaned up resources for closing session: %s", session.Stat())
}
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The cleanupSession method in gettyClientHandler duplicates the same logic as cleanupSessionResources in SessionManager. Consider consolidating this cleanup logic into a single reusable function to avoid code duplication.

Suggested change
func (g *gettyClientHandler) cleanupSession(session getty.Session) {
session.RemoveAttribute(heartBeatRetryTimesKey)
log.Debugf("Cleaned up resources for closing session: %s", session.Stat())
}
// cleanupSessionResources removes session attributes and logs cleanup.
func cleanupSessionResources(session getty.Session) {
session.RemoveAttribute(heartBeatRetryTimesKey)
log.Debugf("Cleaned up resources for closing session: %s", session.Stat())
}
func (g *gettyClientHandler) cleanupSession(session getty.Session) {
cleanupSessionResources(session)
}

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

done

@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2025

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.53%. Comparing base (be1ad86) to head (38d8bc7).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/remoting/getty/listener.go 0.00% 7 Missing ⚠️
pkg/remoting/getty/session_manager.go 0.00% 5 Missing ⚠️
pkg/remoting/getty/getty_remoting.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #898   +/-   ##
=======================================
  Coverage   54.52%   54.53%           
=======================================
  Files         209      209           
  Lines       12913    12985   +72     
=======================================
+ Hits         7041     7081   +40     
- Misses       5372     5403   +31     
- Partials      500      501    +1     

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

import (
"context"
"fmt"
getty "github.com/apache/dubbo-getty"
Copy link
Contributor

Choose a reason for hiding this comment

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

import 格式有点乱

Copy link
Author

Choose a reason for hiding this comment

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

get

@AlexStocks
Copy link
Contributor

would you like to add some uts for this PR?

@Wangzy455
Copy link
Author

would you like to add some uts for this PR?

OK, I will improve the unit test to verify the newly added reconnection method

@Wangzy455
Copy link
Author

would you like to add some uts for this PR?

OK, I will improve the unit test to verify the newly added reconnection method

I removed the reconnect method and only kept the resource cleanup part.

// messageFuture.Err = rpcMessage.Err
messageFuture.Done <- struct{}{}
// client.msgFutures.Delete(rpcMessage.RequestID)
g.futures.Delete(rpcMessage.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe ‘g.futures’ is nil?

cleanupSession(session)
}
func cleanupSession(session getty.Session) {
session.RemoveAttribute(heartBeatRetryTimesKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls add check for ‘ session’

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working coding remoting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants