Skip to content

Conversation

@SBALAVIGNESH123
Copy link

@SBALAVIGNESH123 SBALAVIGNESH123 commented Dec 8, 2025

Hey! This update fixes the UnexpectedEOFError that was breaking libp2p connections.
What was happening
When using this library with js-libp2p, the connection would fail during the encryption handshake. After checking the logs, I found that libp2p expects sockets to support “half-open” mode (where reading can stop but writing can continue).
This library was closing the entire socket as soon as it got a FIN packet, which caused the error.
What I changed
I added support for allowHalfOpen and made the socket behave more like Node’s net module. -JavaScript
Added an allowHalfOpen option to Socket (defaults to false).
Added an event listener for when the read side closes.
Instead of destroying the socket, it now switches to a readOnly state.-Android
Updated TcpSocketClient to emit an onEnd() event when EOF is detected instead of calling destroy() immediately. iOS Implemented the missing onEnd delegate method. Now it sends an event to JS when the read side closes instead of disconnecting right away.
Testing-
Tested using @abuvanth’s reproduction repo (react-native-libp2p-tcp-test). Before this fix, the connection would fail instantly. After the changes, the handshake completes without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant