-
Notifications
You must be signed in to change notification settings - Fork 0
Improve performance and reliability with native git CLI and better error handling #230
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ package daemon | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/lithammer/shortuuid/v3" | ||
| "github.com/pkg/errors" | ||
|
|
@@ -344,6 +346,9 @@ func (s *subscriber) sendMessageToSubscriber(msg *message.Message, logFields wat | |
| ctx, cancelCtx := context.WithCancel(s.ctx) | ||
| defer cancelCtx() | ||
|
|
||
| const maxRetries = 3 | ||
| retryCount := 0 | ||
|
|
||
| SendToSubscriber: | ||
| for { | ||
| // copy the message to prevent ack/nack propagation to other consumers | ||
|
|
@@ -371,8 +376,20 @@ SendToSubscriber: | |
| s.logger.Trace("Message acked", logFields) | ||
| return | ||
| case <-msgToSend.Nacked(): | ||
| s.logger.Trace("Nack received, resending message", logFields) | ||
| continue SendToSubscriber | ||
| retryCount++ | ||
| if retryCount > maxRetries { | ||
| s.logger.Error("Max retries reached, dropping message", errors.New("max retries reached"), logFields) | ||
| return | ||
| } | ||
| backoff := time.Duration(100<<uint(retryCount-1)) * time.Millisecond | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value |
||
| s.logger.Trace(fmt.Sprintf("Nack received, retrying after %s (%d/%d)", backoff, retryCount, maxRetries), logFields) | ||
| select { | ||
| case <-time.After(backoff): | ||
| continue SendToSubscriber | ||
| case <-s.closing: | ||
| s.logger.Trace("Closing during backoff, message discarded", logFields) | ||
| return | ||
| } | ||
| case <-s.closing: | ||
| s.logger.Trace("Closing, message discarded", logFields) | ||
| return | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,21 +127,22 @@ func (p *SocketHandler) Stop() { | |
|
|
||
| func (p *SocketHandler) acceptConnections() { | ||
| for { | ||
| select { | ||
| case <-p.stopChan: | ||
| return | ||
| default: | ||
| conn, err := p.listener.Accept() | ||
| if err != nil { | ||
| continue | ||
| conn, err := p.listener.Accept() | ||
| if err != nil { | ||
| select { | ||
| case <-p.stopChan: | ||
| return | ||
| default: | ||
| } | ||
| go p.handleConnection(conn) | ||
| continue | ||
|
Comment on lines
+131
to
+137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| } | ||
| go p.handleConnection(conn) | ||
| } | ||
| } | ||
|
|
||
| func (p *SocketHandler) handleConnection(conn net.Conn) { | ||
| defer conn.Close() | ||
| conn.SetDeadline(time.Now().Add(5 * time.Second)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| decoder := json.NewDecoder(conn) | ||
| var msg SocketMessage | ||
| if err := decoder.Decode(&msg); err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code for fetching the rate limit is a duplicate of the logic at lines 166-174. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, consider extracting this logic into a new private method on
CCInfoTimerService. You could then call this new method as a goroutine from both locations.