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
6acf56aa
Unverified
Commit
6acf56aa
authored
Mar 11, 2019
by
Steven Allen
Committed by
GitHub
Mar 11, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #89 from ipfs/fix/worker-context
fix: limit use of custom context type
parents
5952645a
799bfb3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
workers.go
workers.go
+10
-2
No files found.
workers.go
View file @
6acf56aa
...
...
@@ -98,6 +98,15 @@ func (bs *Bitswap) sendBlocks(ctx context.Context, env *engine.Envelope) {
}
func
(
bs
*
Bitswap
)
provideWorker
(
px
process
.
Process
)
{
// FIXME: OnClosingContext returns a _custom_ context type.
// Unfortunately, deriving a new cancelable context from this custom
// type fires off a goroutine. To work around this, we create a single
// cancelable context up-front and derive all sub-contexts from that.
//
// See: https://github.com/ipfs/go-ipfs/issues/5810
ctx
:=
procctx
.
OnClosingContext
(
px
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
limit
:=
make
(
chan
struct
{},
provideWorkerMax
)
...
...
@@ -108,7 +117,6 @@ func (bs *Bitswap) provideWorker(px process.Process) {
}()
ev
:=
logging
.
LoggableMap
{
"ID"
:
wid
}
ctx
:=
procctx
.
OnClosingContext
(
px
)
// derive ctx from px
defer
log
.
EventBegin
(
ctx
,
"Bitswap.ProvideWorker.Work"
,
ev
,
k
)
.
Done
()
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
provideTimeout
)
// timeout ctx
...
...
@@ -123,7 +131,7 @@ func (bs *Bitswap) provideWorker(px process.Process) {
// _ratelimited_ number of workers to handle each key.
for
wid
:=
2
;
;
wid
++
{
ev
:=
logging
.
LoggableMap
{
"ID"
:
1
}
log
.
Event
(
procctx
.
OnClosingContext
(
px
)
,
"Bitswap.ProvideWorker.Loop"
,
ev
)
log
.
Event
(
ctx
,
"Bitswap.ProvideWorker.Loop"
,
ev
)
select
{
case
<-
px
.
Closing
()
:
...
...
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