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

synchronously closing one side of the connection breaks libp2p #170

Closed
mkg20001 opened this issue Feb 25, 2018 · 7 comments
Closed

synchronously closing one side of the connection breaks libp2p #170

mkg20001 opened this issue Feb 25, 2018 · 7 comments
Labels
kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up status/ready Ready to be worked

Comments

@mkg20001
Copy link
Member

mkg20001 commented Feb 25, 2018

  • Version: libp2p v18

  • Platform: server: Linux - 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux, client: Linux - 4.13.0-36-generic #40-Ubuntu SMP Fri Feb 16 20:07:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux, node (same on both): v8.9.4

  • Subsystem: transport, muxer

Type: bug

Severity: high

Description: synchronously closing one side of the connection breaks libp2p

Steps to reproduce the error: https://github.com/mkg20001/libp2p-nodetrust

Install and setup the server and client from the fix/update branch at commit 2b34ab0eeacc410840a9daa76a9afa80a8a6ffa8

server-log.txt
client-log.txt

The fix is to close one side of the connection asynchronously. This patch fixes it (but this is just a workaround):

diff --git a/server/src/proto/index.js b/server/src/proto/index.js
index 2a34925..739ecc6 100644
--- a/server/src/proto/index.js
+++ b/server/src/proto/index.js
@@ -28,8 +28,6 @@ class RPC {
     this.sink = this.sink.bind(this)
   }
   sink (read) {
-    read(true, () => {}) // we will never read from the client
-
     const cb = (err, res) => {
       if (err) {
         log(err)
@@ -39,6 +37,8 @@ class RPC {
       }
 
       this.source.end()
+
+      read(true, () => {}) // we will never read from the client
     }
     const ips = this.addr.map(a => a.toString()).filter(a => a.startsWith('/ip')).map(a => a.split('/')[2]) // TODO: filter unique
     const domains = ips.map(ip => encodeAddr(ip)).filter(Boolean).map(sub => sub + '.' + this.opt.zone)

I don't know if this is a bug from my module but I think that closing one side of the connection in sync shouldn't close the other. Or the whole muxer connection.

@mkg20001
Copy link
Member Author

Note: both mplex and spdy show this behaviour

@daviddias daviddias added the status/ready Ready to be worked label Feb 26, 2018
@daviddias
Copy link
Member

daviddias commented Feb 26, 2018

@mkg20001 can you add a test that reproduces this? I'm not sure if I understand the issue. Sounds like you are just not catching the errors and they go uncaught.

@mkg20001
Copy link
Member Author

@daviddias
Copy link
Member

@mkg20001 can you convert that into a PR with a test for this module?

@daviddias daviddias added kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up labels Mar 2, 2018
@mkg20001
Copy link
Member Author

@diasdavid I tried to implement the test case but the error does not seem to occur. Either this is fixed already or it's because both peers are running in the same process.

@dryajov
Copy link
Member

dryajov commented Mar 29, 2018

This seems to be related to the multiplexer throwing that is being worked on in - https://github.com/libp2p/js-libp2p-mplex/pull/75/files.

@vasco-santos
Copy link
Member

This should not be a problem anymore

maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
Bumps [@multiformats/mafmt](https://github.com/multiformats/js-mafmt) from 11.1.2 to 12.0.0.
- [Release notes](https://github.com/multiformats/js-mafmt/releases)
- [Changelog](https://github.com/multiformats/js-mafmt/blob/master/CHANGELOG.md)
- [Commits](multiformats/js-mafmt@v11.1.2...v12.0.0)

---
updated-dependencies:
- dependency-name: "@multiformats/mafmt"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
## [6.0.3](libp2p/js-libp2p-bootstrap@v6.0.2...v6.0.3) (2023-03-20)

### Dependencies

* bump @multiformats/mafmt from 11.1.2 to 12.0.0 ([libp2p#170](libp2p/js-libp2p-bootstrap#170)) ([5c15878](libp2p/js-libp2p-bootstrap@5c15878))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

4 participants