call Stream.CloseWrite right after writing

This commit is contained in:
hanabi1224 2022-12-16 17:22:53 +08:00
parent 425d8a7fcf
commit 6ae7cdab64
2 changed files with 2 additions and 0 deletions

View File

@ -430,6 +430,7 @@ func (c *client) sendRequestToPeer(ctx context.Context, peer peer.ID, req *Reque
}
_ = stream.SetWriteDeadline(time.Time{}) // clear deadline // FIXME: Needs
// its own API (https://github.com/libp2p/go-libp2p/core/issues/162).
stream.CloseWrite()
// Read response.
var res Response

View File

@ -158,6 +158,7 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
if err := cborutil.WriteCborRPC(s, hmsg); err != nil {
return xerrors.Errorf("writing rpc to peer: %w", err)
}
s.CloseWrite()
go func() {
defer s.Close() //nolint:errcheck