Skip to content

Commit d0dcced

Browse files
authored
ocr3 should respect context (#1102)
1 parent 1b355c7 commit d0dcced

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pkg/capabilities/consensus/ocr3/capability.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,20 @@ func (o *capability) Execute(ctx context.Context, r capabilities.CapabilityReque
226226
return capabilities.CapabilityResponse{}, err
227227
}
228228

229-
response := <-ch
230-
outputLenBytes := byteSizeOfMap(response.Value)
231-
return capabilities.CapabilityResponse{
232-
Value: response.Value,
233-
Metadata: capabilities.ResponseMetadata{
234-
Metering: []capabilities.MeteringNodeDetail{
235-
{SpendUnit: metering.PayloadUnit.Name, SpendValue: fmt.Sprintf("%d", inputLenBytes+outputLenBytes)},
229+
select {
230+
case <-ctx.Done():
231+
return capabilities.CapabilityResponse{}, ctx.Err()
232+
case response := <-ch:
233+
outputLenBytes := byteSizeOfMap(response.Value)
234+
return capabilities.CapabilityResponse{
235+
Value: response.Value,
236+
Metadata: capabilities.ResponseMetadata{
237+
Metering: []capabilities.MeteringNodeDetail{
238+
{SpendUnit: metering.PayloadUnit.Name, SpendValue: fmt.Sprintf("%d", inputLenBytes+outputLenBytes)},
239+
},
236240
},
237-
},
238-
}, response.Err
241+
}, response.Err
242+
}
239243
}
240244

241245
return capabilities.CapabilityResponse{}, fmt.Errorf("unknown method: %s", m.Method)

0 commit comments

Comments
 (0)