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
73e55bf0
Commit
73e55bf0
authored
Jun 11, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent wantmanager from leaking goroutines (and memory)
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
8cb50134
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
24 deletions
+37
-24
wantmanager.go
wantmanager.go
+37
-24
No files found.
wantmanager.go
View file @
73e55bf0
...
@@ -137,36 +137,49 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
...
@@ -137,36 +137,49 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
for
{
for
{
select
{
select
{
case
<-
mq
.
work
:
// there is work to be done
case
<-
mq
.
work
:
// there is work to be done
mq
.
doWork
(
ctx
)
err
:=
mq
.
network
.
ConnectTo
(
ctx
,
mq
.
p
)
if
err
!=
nil
{
log
.
Noticef
(
"cant connect to peer %s: %s"
,
mq
.
p
,
err
)
// TODO: cant connect, what now?
continue
}
// grab outgoing message
mq
.
outlk
.
Lock
()
wlm
:=
mq
.
out
if
wlm
==
nil
||
wlm
.
Empty
()
{
mq
.
outlk
.
Unlock
()
continue
}
mq
.
out
=
nil
mq
.
outlk
.
Unlock
()
// send wantlist updates
err
=
mq
.
network
.
SendMessage
(
ctx
,
mq
.
p
,
wlm
)
if
err
!=
nil
{
log
.
Noticef
(
"bitswap send error: %s"
,
err
)
// TODO: what do we do if this fails?
}
case
<-
mq
.
done
:
case
<-
mq
.
done
:
return
return
}
}
}
}
}
}
func
(
mq
*
msgQueue
)
doWork
(
ctx
context
.
Context
)
{
// allow a minute for connections
// this includes looking them up in the dht
// dialing them, and handshaking
conctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Minute
)
defer
cancel
()
err
:=
mq
.
network
.
ConnectTo
(
conctx
,
mq
.
p
)
if
err
!=
nil
{
log
.
Noticef
(
"cant connect to peer %s: %s"
,
mq
.
p
,
err
)
// TODO: cant connect, what now?
return
}
// grab outgoing message
mq
.
outlk
.
Lock
()
wlm
:=
mq
.
out
mq
.
out
=
nil
mq
.
outlk
.
Unlock
()
if
wlm
==
nil
||
wlm
.
Empty
()
{
return
}
sendctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
30
)
defer
cancel
()
// send wantlist updates
err
=
mq
.
network
.
SendMessage
(
sendctx
,
mq
.
p
,
wlm
)
if
err
!=
nil
{
log
.
Noticef
(
"bitswap send error: %s"
,
err
)
// TODO: what do we do if this fails?
return
}
}
func
(
pm
*
WantManager
)
Connected
(
p
peer
.
ID
)
{
func
(
pm
*
WantManager
)
Connected
(
p
peer
.
ID
)
{
pm
.
connect
<-
p
pm
.
connect
<-
p
}
}
...
...
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