Commit 46b21cf5 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet
Browse files

ctx.Done fixes

thanks @whyrusleeping for finding these.
parent 8a81975c
...@@ -224,7 +224,10 @@ func writeMsgCtx(ctx context.Context, w msgio.Writer, msg proto.Message) ([]byte ...@@ -224,7 +224,10 @@ func writeMsgCtx(ctx context.Context, w msgio.Writer, msg proto.Message) ([]byte
done := make(chan error) done := make(chan error)
go func(m []byte) { go func(m []byte) {
err := w.WriteMsg(m) err := w.WriteMsg(m)
done <- err select {
case done <- err:
case <-ctx.Done():
}
}(enc) }(enc)
select { select {
...@@ -243,7 +246,10 @@ func readMsgCtx(ctx context.Context, r msgio.Reader, p proto.Message) ([]byte, e ...@@ -243,7 +246,10 @@ func readMsgCtx(ctx context.Context, r msgio.Reader, p proto.Message) ([]byte, e
go func() { go func() {
var err error var err error
msg, err = r.ReadMsg() msg, err = r.ReadMsg()
done <- err select {
case done <- err:
case <-ctx.Done():
}
}() }()
select { select {
......
...@@ -44,7 +44,12 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) ( ...@@ -44,7 +44,12 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) (
// do it async to ensure we respect don contexteone // do it async to ensure we respect don contexteone
go func() { go func() {
defer func() { done <- struct{}{} }() defer func() {
select {
case done <- struct{}{}:
case <-ctx.Done():
}
}()
c, err := newSingleConn(ctx, d.LocalPeer, remote, maconn) c, err := newSingleConn(ctx, d.LocalPeer, remote, maconn)
if err != nil { if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment