mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
parent
6598c38625
commit
ceaceeb33c
@ -15,8 +15,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// The time to wait before disconnecting a peer.
|
||||
flushDuration = 50 * time.Millisecond
|
||||
// The time to wait for a status request.
|
||||
timeForStatus = 10 * time.Second
|
||||
)
|
||||
@ -85,9 +83,6 @@ func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer
|
||||
if err := goodbyeFunc(context.Background(), remotePeer); err != nil {
|
||||
log.WithError(err).Trace("Unable to send goodbye message to peer")
|
||||
}
|
||||
// Add a short delay to allow the stream to flush before closing the connection.
|
||||
// There is still a chance that the peer won't receive the message.
|
||||
time.Sleep(flushDuration)
|
||||
disconnectFromPeer()
|
||||
return
|
||||
}
|
||||
|
@ -458,8 +458,8 @@ func (f *blocksFetcher) requestBlocks(
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err := stream.Close(); err != nil {
|
||||
log.WithError(err).Error("Failed to close stream")
|
||||
if err := stream.Reset(); err != nil {
|
||||
log.WithError(err).Errorf("Failed to close stream with protocol %s", stream.Protocol())
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -22,6 +22,11 @@ func (r *Service) sendRecentBeaconBlocksRequest(ctx context.Context, blockRoots
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := stream.Reset(); err != nil {
|
||||
log.WithError(err).Errorf("Failed to reset stream with protocol %s", stream.Protocol())
|
||||
}
|
||||
}()
|
||||
for i := 0; i < len(blockRoots); i++ {
|
||||
blk, err := ReadChunkedBlock(stream, r.p2p)
|
||||
if err == io.EOF {
|
||||
|
@ -51,9 +51,6 @@ func (r *Service) sendGoodByeAndDisconnect(ctx context.Context, code uint64, id
|
||||
"peer": id,
|
||||
}).Debug("Could not send goodbye message to peer")
|
||||
}
|
||||
// Add a short delay to allow the stream to flush before closing the connection.
|
||||
// There is still a chance that the peer won't receive the message.
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
if err := r.p2p.Disconnect(id); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -68,8 +65,16 @@ func (r *Service) sendGoodByeMessage(ctx context.Context, code uint64, id peer.I
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := stream.Reset(); err != nil {
|
||||
log.WithError(err).Errorf("Failed to reset stream with protocol %s", stream.Protocol())
|
||||
}
|
||||
}()
|
||||
log := log.WithField("Reason", goodbyeMessage(code))
|
||||
log.WithField("peer", stream.Conn().RemotePeer()).Debug("Sending Goodbye message to peer")
|
||||
// Add a short delay to allow the stream to flush before resetting it.
|
||||
// There is still a chance that the peer won't receive the message.
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,8 @@ func (r *Service) sendMetaDataRequest(ctx context.Context, id peer.ID) (*pb.Meta
|
||||
// metadata requests send no payload, so closing the
|
||||
// stream early leads it to a reset.
|
||||
defer func() {
|
||||
if err := stream.Close(); err != nil {
|
||||
log.WithError(err).Error("Failed to close stream")
|
||||
if err := stream.Reset(); err != nil {
|
||||
log.WithError(err).Errorf("Failed to reset stream for protocol %s", stream.Protocol())
|
||||
}
|
||||
}()
|
||||
code, errMsg, err := ReadStatusCode(stream, r.p2p.Encoding())
|
||||
|
@ -58,6 +58,11 @@ func (r *Service) sendPingRequest(ctx context.Context, id peer.ID) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := stream.Reset(); err != nil {
|
||||
log.WithError(err).Errorf("Failed to reset stream with protocol %s", stream.Protocol())
|
||||
}
|
||||
}()
|
||||
|
||||
code, errMsg, err := ReadStatusCode(stream, r.p2p.Encoding())
|
||||
if err != nil {
|
||||
|
@ -95,6 +95,11 @@ func (r *Service) sendRPCStatusRequest(ctx context.Context, id peer.ID) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := stream.Reset(); err != nil {
|
||||
log.WithError(err).Errorf("Failed to reset stream with protocol %s", stream.Protocol())
|
||||
}
|
||||
}()
|
||||
|
||||
code, errMsg, err := ReadStatusCode(stream, r.p2p.Encoding())
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user