Skip to content

Commit

Permalink
Fix: add timeout for receiver (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Sep 6, 2024
1 parent 1a8c451 commit ebf8354
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/metadata/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ func (r *Receiver) worker(ctx context.Context, task storage.TokenMetadata) {
Str("uri", *task.Uri).
Msg("try to receive token metadata")

timeoutCtx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

var err error
switch {
case strings.HasPrefix(*task.Uri, "http://") || strings.HasPrefix(*task.Uri, "https://"):
err = r.httpRequest(ctx, &task)
err = r.httpRequest(timeoutCtx, &task)
case strings.HasPrefix(*task.Uri, "ipfs://"):
err = r.ipfsRequest(ctx, &task)
err = r.ipfsRequest(timeoutCtx, &task)
default:
task.Attempts = uint(r.maxAttempts)
err = ErrInvalidUri
Expand Down

0 comments on commit ebf8354

Please sign in to comment.