Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Add 3 minute timeout to Provide call
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavila committed Jun 12, 2019
1 parent a0eafde commit c2e647a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions simple/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package simple

import (
"context"
"time"

cid "github.com/ipfs/go-cid"
q "github.com/ipfs/go-ipfs-provider/queue"
Expand All @@ -14,7 +15,10 @@ import (

var logP = logging.Logger("provider.simple")

const provideOutgoingWorkerLimit = 8
const (
provideOutgoingWorkerLimit = 8
provideTimeout = 3 * time.Minute
)

// Provider announces blocks to the network
type Provider struct {
Expand Down Expand Up @@ -60,8 +64,10 @@ func (p *Provider) handleAnnouncements() {
case <-p.ctx.Done():
return
case c := <-p.queue.Dequeue():
ctx, cancel := context.WithTimeout(p.ctx, provideTimeout)
defer cancel()
logP.Info("announce - start - ", c)
if err := p.contentRouting.Provide(p.ctx, c, true); err != nil {
if err := p.contentRouting.Provide(ctx, c, true); err != nil {
logP.Warningf("Unable to provide entry: %s, %s", c, err)
}
logP.Info("announce - end - ", c)
Expand Down

0 comments on commit c2e647a

Please sign in to comment.