From 86c0a65dd0779ebf6feaaecf1d5df49abfb574b5 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 9 Apr 2019 15:23:57 -0700 Subject: [PATCH] fully close the autonat client stream The "correct" way to do this is to send an write, close, read, then read the EOF. However, we don't really do that _anywhere_ in our code. --- client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 0fd665d..aa3075e 100644 --- a/client.go +++ b/client.go @@ -49,7 +49,9 @@ 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) @@ -57,12 +59,14 @@ func (c *client) DialBack(ctx context.Context, p peer.ID) (ma.Multiaddr, error) 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 }