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

Add timeout to Provide call #8

Merged
merged 5 commits into from
Jun 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hsanjuan marked this conversation as resolved.
Show resolved Hide resolved
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