Copilot commented on code in PR #898:
URL:
https://github.com/apache/incubator-seata-go/pull/898#discussion_r2383913549
##########
pkg/remoting/getty/getty_client.go:
##########
@@ -106,6 +110,29 @@ func (g *GettyRemotingClient) syncCallback(reqMsg
message.RpcMessage, respMsg *m
}
}
+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)
+ }
+}
Review Comment:
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.
##########
pkg/remoting/getty/listener.go:
##########
@@ -143,3 +145,8 @@ func (g *gettyClientHandler) RegisterProcessor(msgType
message.MessageType, proc
g.processorMap[msgType] = processor
}
}
+
+func (g *gettyClientHandler) cleanupSession(session getty.Session) {
+ session.RemoveAttribute(heartBeatRetryTimesKey)
+ log.Debugf("Cleaned up resources for closing session: %s",
session.Stat())
+}
Review Comment:
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.
```suggestion
// 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)
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]