From d81b4538fd05a0a6b4c4b026aad9b5554f1fd368 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 14 Jun 2019 17:51:39 -0700 Subject: [PATCH] fix: wait for handshake to complete before returning That makes sure we aren't still writing/reading after we relinquish control. fixes #40 may be related to https://github.com/ipfs/go-ipfs/issues/6197? --- protocol.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol.go b/protocol.go index 8e473c7..7ac81af 100644 --- a/protocol.go +++ b/protocol.go @@ -125,9 +125,12 @@ func (s *secureSession) runHandshake(ctx context.Context) error { var err error select { case <-ctx.Done(): + err = ctx.Err() + // State unknown. We *have* to close this. s.insecure.Close() - err = ctx.Err() + // Wait for the handshake to return. + <-result case err = <-result: } return err