Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
b01706f0
Commit
b01706f0
authored
Oct 18, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix panic in bitswap working limit spawning
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
ff038ecf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
workers.go
workers.go
+26
-22
No files found.
workers.go
View file @
b01706f0
...
...
@@ -5,7 +5,6 @@ import (
process
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
procctx
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
ratelimit
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
key
"github.com/ipfs/go-ipfs/blocks/key"
...
...
@@ -74,11 +73,14 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
func
(
bs
*
Bitswap
)
provideWorker
(
px
process
.
Process
)
{
limit
er
:=
ratelimit
.
NewRateLimiter
(
px
,
provideWorkerMax
)
limit
:=
make
(
chan
struct
{}
,
provideWorkerMax
)
limitedGoProvide
:=
func
(
k
key
.
Key
,
wid
int
)
{
defer
func
()
{
// replace token when done
<-
limit
}()
ev
:=
logging
.
LoggableMap
{
"ID"
:
wid
}
limiter
.
LimitedGo
(
func
(
px
process
.
Process
)
{
ctx
:=
procctx
.
OnClosingContext
(
px
)
// derive ctx from px
defer
log
.
EventBegin
(
ctx
,
"Bitswap.ProvideWorker.Work"
,
ev
,
&
k
)
.
Done
()
...
...
@@ -89,12 +91,10 @@ func (bs *Bitswap) provideWorker(px process.Process) {
if
err
:=
bs
.
network
.
Provide
(
ctx
,
k
);
err
!=
nil
{
log
.
Error
(
err
)
}
})
}
// worker spawner, reads from bs.provideKeys until it closes, spawning a
// _ratelimited_ number of workers to handle each key.
limiter
.
Go
(
func
(
px
process
.
Process
)
{
for
wid
:=
2
;
;
wid
++
{
ev
:=
logging
.
LoggableMap
{
"ID"
:
1
}
log
.
Event
(
procctx
.
OnClosingContext
(
px
),
"Bitswap.ProvideWorker.Loop"
,
ev
)
...
...
@@ -107,10 +107,14 @@ func (bs *Bitswap) provideWorker(px process.Process) {
log
.
Debug
(
"provideKeys channel closed"
)
return
}
limitedGoProvide
(
k
,
wid
)
select
{
case
<-
px
.
Closing
()
:
return
case
limit
<-
struct
{}{}
:
go
limitedGoProvide
(
k
,
wid
)
}
}
}
})
}
func
(
bs
*
Bitswap
)
provideCollector
(
ctx
context
.
Context
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment