Merge pull request #875 from filecoin-project/fix/hello-close

Fix hello calling close before compleating timestamp exchange
This commit is contained in:
Łukasz Magiera 2019-12-12 17:26:05 +01:00 committed by GitHub
commit f1d0fb3706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,6 @@ func NewHelloService(h host.Host, cs *store.ChainStore, syncer *chain.Syncer, pm
} }
func (hs *Service) HandleStream(s inet.Stream) { func (hs *Service) HandleStream(s inet.Stream) {
defer s.Close()
var hmsg Message var hmsg Message
if err := cborutil.ReadCborRPC(s, &hmsg); err != nil { if err := cborutil.ReadCborRPC(s, &hmsg); err != nil {
@ -81,6 +80,8 @@ func (hs *Service) HandleStream(s inet.Stream) {
return return
} }
go func() { go func() {
defer s.Close()
sent := time.Now() sent := time.Now()
msg := &Message{ msg := &Message{
TArrial: arrived.UnixNano(), TArrial: arrived.UnixNano(),
@ -110,7 +111,6 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
if err != nil { if err != nil {
return err return err
} }
defer s.Close()
hts := hs.cs.GetHeaviestTipSet() hts := hs.cs.GetHeaviestTipSet()
weight, err := hs.cs.Weight(ctx, hts) weight, err := hs.cs.Weight(ctx, hts)
@ -136,9 +136,11 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
} }
go func() { go func() {
defer s.Close()
hmsg = &Message{} hmsg = &Message{}
s.SetReadDeadline(time.Now().Add(10 * time.Second)) s.SetReadDeadline(time.Now().Add(10 * time.Second))
err := cborutil.ReadCborRPC(s, hmsg) // ignore error err := cborutil.ReadCborRPC(s, hmsg)
ok := err == nil ok := err == nil
t3 := time.Now() t3 := time.Now()