Skip to content

Improve transport connection errors #4538

@AgeManning

Description

@AgeManning

Description

Libp2p spits out some rather nasty std::io Errors, which make our logs pretty hard to digest. It would be nice to try and grab the useful information of the wrapped errors and print it in a consumable way.

The main one I'm worried about are transport errors that occur often when we attempt connections to peers. The main culprit, is in the DailFailure event.

See the error here:
https://github.com/divagant-martian/lighthouse/blob/libp2p-0.52/beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs#L135

The error is a DialError and the main ones of issue are the Transport variants. The printed version looks like this:

Transport([("/ip4/x.x.x.x/tcp/9000/p2p/16Uiu2HAm414GH2X4sLtWyRujBak6euCdZiWfbjCRnpLyk4L4Hw6i", Other(Custom { kind: Other, error: Custom { kind: Other, error: Other(Left(Right(Select(ProtocolError(IoError(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })))))) } }))])

It would be nice to extract this kind of variant to something of the form:

Transport error: Connection reset by peer

The error contains a vec<(Multiaddr, TransportError)> and we can probably ignore the multiaddrs and it is probably fine to just print the first error. Although we might want to include a count, like errors: 3 (if there were 3 errors in the vec).

I'd imagine this could be done via a wrapper struct, but the std::io::Errors that are nested start getting harder to deal with.

i.e:

// A wrapper struct that prints a dial error nicely.
struct ClearDialError(DialError);

impl std::fmt::Display for ClearDialError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self.0 {
            DialError::Transport(errors) => {
                for (multiaddr, transport_error) in errors {
                    match transport_error {
                        TransportError::MultiaddrNotSupported(multiaddr_error) => {
                            write!(f, "Multiaddr not supported: {multiaddr_error}")?;
                        }
                        TransportError::Other(io_error) => {
                            // Pull out the most inner error
        }
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions