libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.github.io/js-libp2p/
Other
2.34k stars 446 forks source link

fix(ping): gracefully handle remote stream closure. #2819

Closed privacyguard closed 1 week ago

privacyguard commented 1 week ago

Gracefully handle remote stream closure

Description

This PR fixes the UnexpectedEOFError issue. This issue happens because the ping protocol does not handle the case where the remote peer closes the stream and with the introduction of connectionMonitor this became an issue. It opens a stream for the ping protocol, sends a ping, gets the response then closes the stream. The local peer throws an exception and triggers a yamux reset.

Notes & open questions

We only tested these changes in the context described above. Not sure if there are other cases to handle.

Change checklist

achingbrain commented 1 week ago

Thanks for opening this. I think we should handle the case where the remote has pinged us and closed the connection, it's in the spec so we shouldn't be logging error messages.

I can't push changes to this branch (possibly due to your org settings) so I've opened #2822 which incorporates the commit from here.

achingbrain commented 1 week ago

Closing in favour of #2822

privacyguard commented 1 week ago

@achingbrain no worries! Glad we could help.