Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #21 from libp2p/fix/full-close
Browse files Browse the repository at this point in the history
fully close the autonat client stream
  • Loading branch information
Stebalien authored Apr 9, 2019
2 parents af9b2ab + 86c0a65 commit c827b8b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ func (c *client) DialBack(ctx context.Context, p peer.ID) (ma.Multiaddr, error)
if err != nil {
return nil, err
}
defer s.Close()
// Might as well just reset the stream. Once we get to this point, we
// don't care about being nice.
defer inet.FullClose(s)

r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)

req := newDialMessage(pstore.PeerInfo{ID: c.h.ID(), Addrs: c.getAddrs()})
err = w.WriteMsg(req)
if err != nil {
s.Reset()
return nil, err
}

var res pb.Message
err = r.ReadMsg(&res)
if err != nil {
s.Reset()
return nil, err
}

Expand Down

0 comments on commit c827b8b

Please sign in to comment.