Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readLoop errors should lead to neighbor's disconnection #2375

Merged
merged 13 commits into from
Aug 8, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ services:
--node.enablePlugins=analysisServer,analysisDashboard,prometheus
--node.disablePlugins=activity,analysisClient,chat,consensus,dashboard,faucet,gossip,firewall,issuer,mana,manualpeering,blockLayer,metrics,networkdelay,portcheck,pow,syncBeaconFollower,webAPIBroadcastDataEndpoint,WebAPIDataEndpoint,WebAPIHealthzEndpoint,WebAPIFaucetRequestEndpoint,webAPIFindTransactionHashesEndpoint,webAPIGetNeighborsEndpoint,webAPIGetTransactionObjectsByHashEndpoint,webAPIGetTransactionTrytesByHashEndpoint,WebAPIInfoEndpoint,WebAPILedgerstateEndpoint,WebAPIBlockEndpoint,WebAPIToolsBlockEndpoint,WebAPIWeightProviderEndpoint,remotelog,remotelogmetrics,DAGsVisualizer,WebAPIRateSetterEndpoint,WebAPISchedulerEndpoint,ManaInitializer,Notarization,EpochStorage,WebAPIEpochEndpoint,BootstrapManager
--logger.level={{ logLevel }}
--logger.outputPaths=stdout
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ services:
--analysis.client.serverAddress=
--node.disablePlugins=activity,analysisClient,chat,consensus,dashboard,faucet,gossip,firewall,issuer,mana,manualpeering,blockLayer,metrics,networkdelay,portcheck,pow,syncBeaconFollower,webAPIBroadcastDataEndpoint,WebAPIDataEndpoint,WebAPIHealthzEndpoint,WebAPIFaucetRequestEndpoint,webAPIFindTransactionHashesEndpoint,webAPIGetNeighborsEndpoint,webAPIGetTransactionObjectsByHashEndpoint,webAPIGetTransactionTrytesByHashEndpoint,WebAPIInfoEndpoint,WebAPILedgerstateEndpoint,WebAPIBlockEndpoint,WebAPIToolsBlockEndpoint,WebAPIWeightProviderEndpoint,remotelog,remotelogmetrics,DAGsVisualizer,WebAPIRateSetterEndpoint,WebAPISchedulerEndpoint,ManaInitializer,Notarization,EpochStorage,WebAPIEpochEndpoint,BootstrapManager
--logger.level={{ logLevel }}
--logger.outputPaths=stdout
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ services:
--pow.difficulty={{ powDifficulty }}
{% endif %}
--logger.level={{ logLevel }}
--logger.outputPaths=stdout
--logger.disableEvents=false
--logger.remotelog.serverAddress={{ remoteLoggerHost }}:5213
--remotemetrics.metricsLevel=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ services:
--pow.difficulty={{ powDifficulty }}
{% endif %}
--logger.level={{ logLevel }}
--logger.outputPaths=stdout
--logger.disableEvents=false
--logger.remotelog.serverAddress={{ remoteLoggerHost }}:5213
--remotemetrics.metricsLevel=0
Expand Down
24 changes: 6 additions & 18 deletions packages/node/p2p/neighbor.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package p2p

import (
"io"
"strings"
"sync"
"time"

"github.com/cockroachdb/errors"
"github.com/iotaledger/hive.go/core/autopeering/peer"
"github.com/iotaledger/hive.go/core/logger"
"github.com/libp2p/go-libp2p-core/mux"
"github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-yamux/v2"
)

// NeighborsGroup is an enum type for various neighbors groups like auto/manual.
Expand Down Expand Up @@ -110,16 +106,14 @@ func (n *Neighbor) readLoop() {
packet := stream.packetFactory()
err := stream.ReadPacket(packet)
if err != nil {
if isPermanentError(err) {
if disconnectErr := n.disconnect(); disconnectErr != nil {
n.Log.Warnw("Failed to disconnect", "err", disconnectErr)
}
return
if isTimeoutError(err) {
continue
}
if !isTimeoutError(err) {
n.Log.Debugw("Read error", "err", err)
n.Log.Infow("Stream read packet error", "err", err)
if disconnectErr := n.disconnect(); disconnectErr != nil {
n.Log.Warnw("Failed to disconnect", "err", disconnectErr)
}
continue
return
}
n.Events.PacketReceived.Trigger(&NeighborPacketReceivedEvent{
Neighbor: n,
Expand Down Expand Up @@ -151,9 +145,3 @@ func (n *Neighbor) disconnect() (err error) {
})
return err
}

func isPermanentError(err error) bool {
return strings.Contains(err.Error(), "use of closed network connection") ||
errors.Is(err, io.ErrClosedPipe) || errors.Is(err, mux.ErrReset) || errors.Is(err, yamux.ErrStreamClosed) ||
errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF)
}