Skip to content

Commit

Permalink
additional logging to check response id and removal of incorrect erro…
Browse files Browse the repository at this point in the history
…r log when cancelling a response that has sent a response (#13852)
  • Loading branch information
ettec authored Jul 15, 2024
1 parent b7cff4e commit ced300b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-guests-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal additional logging to remote target capability
9 changes: 9 additions & 0 deletions core/capabilities/remote/target/request/client_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (c *ClientRequest) OnMessage(_ context.Context, msg *types.MessageBody) err
c.mux.Lock()
defer c.mux.Unlock()

if c.respSent {
return nil
}

if msg.Sender == nil {
return fmt.Errorf("sender missing from message")
}
Expand All @@ -150,6 +154,10 @@ func (c *ClientRequest) OnMessage(_ context.Context, msg *types.MessageBody) err
responseID := sha256.Sum256(msg.Payload)
c.responseIDCount[responseID]++

if len(c.responseIDCount) > 1 {
c.lggr.Warn("received multiple different responses for the same request, number of different responses received: %d", len(c.responseIDCount))
}

if c.responseIDCount[responseID] == c.requiredIdenticalResponses {
capabilityResponse, err := pb.UnmarshalCapabilityResponse(msg.Payload)
if err != nil {
Expand All @@ -159,6 +167,7 @@ func (c *ClientRequest) OnMessage(_ context.Context, msg *types.MessageBody) err
}
}
} else {
c.lggr.Warnw("received error response", "error", msg.ErrorMsg)
c.errorCount[msg.ErrorMsg]++
if c.errorCount[msg.ErrorMsg] == c.requiredIdenticalResponses {
c.sendResponse(commoncap.CapabilityResponse{Err: errors.New(msg.ErrorMsg)})
Expand Down
12 changes: 5 additions & 7 deletions core/capabilities/remote/target/request/server_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ func (e *ServerRequest) Cancel(err types.Error, msg string) error {
e.mux.Lock()
defer e.mux.Unlock()

if e.hasResponse() {
return fmt.Errorf("request already has response")
}

e.setError(err, msg)
if err := e.sendResponses(); err != nil {
return fmt.Errorf("failed to send responses: %w", err)
if !e.hasResponse() {
e.setError(err, msg)
if err := e.sendResponses(); err != nil {
return fmt.Errorf("failed to send responses: %w", err)
}
}

return nil
Expand Down

0 comments on commit ced300b

Please sign in to comment.