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
done := make(chan error)
go func(m []byte) {
err := w.WriteMsg(m)
done <- err
select {
case done <- err:
case <-ctx.Done():
}
}(enc)
select {
......@@ -243,7 +246,10 @@ func readMsgCtx(ctx context.Context, r msgio.Reader, p proto.Message) ([]byte, e
go func() {
var err error
msg, err = r.ReadMsg()
done <- err
select {
case done <- err:
case <-ctx.Done():
}
}()
select {
......
......@@ -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
go func() {
defer func() { done <- struct{}{} }()
defer func() {
select {
case done <- struct{}{}:
case <-ctx.Done():
}
}()
c, err := newSingleConn(ctx, d.LocalPeer, remote, maconn)
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