Skip to content

Commit

Permalink
chore: add a subcontext with a timeout + margin
Browse files Browse the repository at this point in the history
  • Loading branch information
agparadiso committed Dec 12, 2024
1 parent 827b0d0 commit 49f1819
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/capabilities/webapi/outgoing_connector_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"sort"
"sync"
"time"

"github.com/pkg/errors"

Expand Down Expand Up @@ -62,6 +63,12 @@ func (c *OutgoingConnectorHandler) HandleSingleNodeRequest(ctx context.Context,
req.TimeoutMs = defaultFetchTimeoutMs
}

// Create a subcontext with the timeout plus some margin for the gateway to process the request
timeoutDuration := time.Duration(req.TimeoutMs) * time.Millisecond
margin := 100 * time.Millisecond
ctx, cancel := context.WithTimeout(ctx, timeoutDuration+margin)
defer cancel()

payload, err := json.Marshal(req)
if err != nil {
return nil, fmt.Errorf("failed to marshal fetch request: %w", err)
Expand Down

0 comments on commit 49f1819

Please sign in to comment.