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

bug: max call stack exceeded when duplicate /webrtc listeners added #2539

Open
SgtPooki opened this issue May 10, 2024 · 1 comment
Open
Labels
need/triage Needs initial labeling and prioritization

Comments

@SgtPooki
Copy link
Member

SgtPooki commented May 10, 2024

  • Version:
  "dependencies": {
    "@chainsafe/libp2p-noise": "^14.0.0",
    "@chainsafe/libp2p-yamux": "^6.0.1",
    "@libp2p/peer-id-factory": "^4.0.0",
    "@libp2p/tcp": "^9.0.4",
    "@libp2p/webrtc": "^4.0.31",
    "@libp2p/websockets": "^8.0.4",
    "@multiformats/multiaddr": "^12.1.11",
    "@nodeutils/defaults-deep": "^1.1.0",
    "it-length-prefixed": "^9.0.1",
    "it-map": "^3.0.3",
    "it-pipe": "^3.0.1",
    "libp2p": "^1.0.8",
    "p-defer": "^4.0.0",
    "uint8arrays": "^4.0.6"
  },
  "devDependencies": {
    "test-ipfs-example": "^1.1.0"
  },
  • Platform:

Darwin Russells-MacBook-Pro-314.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64

  • Subsystem:

@libp2p/webrtc, AddressManagerInit, and packages/libp2p/src/transport-manager

Severity:

Medium

Description:

Possibly fixed by #2133

I accidentally had two /webrtc entries in my listen: array passed to createLibp2p. It took me way too long to figure out what was actually happening. Note that this does not happen for duplicate TCP listen addresses.

The error that surfaces is

╰─ ✔ ❯ node src/listener.js
Listener ready, listening on:
file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/libp2p/dist/src/transport-manager.js:115
        return Array.of(...this.listeners.values()).flat();
                     ^

RangeError: Maximum call stack size exceeded
    at [Symbol.iterator] (<anonymous>)
    at DefaultTransportManager.getListeners (file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/libp2p/dist/src/transport-manager.js:115:22)
    at WebRTCPeerListener.getAddrs (file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/@libp2p/webrtc/dist/src/private-to-private/listener.js:18:14)
    at file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/@libp2p/webrtc/dist/src/private-to-private/listener.js:20:25
    at Array.map (<anonymous>)
    at WebRTCPeerListener.getAddrs (file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/@libp2p/webrtc/dist/src/private-to-private/listener.js:20:14)
    at file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/@libp2p/webrtc/dist/src/private-to-private/listener.js:20:25
    at Array.map (<anonymous>)
    at WebRTCPeerListener.getAddrs (file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/@libp2p/webrtc/dist/src/private-to-private/listener.js:20:14)
    at file:///Users/sgtpooki/code/work/protocol.ai/test/SgtPooki/js-libp2p-examples/node_modules/@libp2p/webrtc/dist/src/private-to-private/listener.js:20:25

Node.js v18.16.1

Which seems to stem from here:

https://github.com/libp2p/js-libp2p/blob/7ae6063dfbc754f95a2c4bd0a6bd146f2989a5f5/packages/libp2p/src/transport-manager.ts#L152C3-L154

Steps to reproduce the error:

You can reproduce this on my branch of a js-libp2p-examples fork, https://github.com/SgtPooki/js-libp2p-examples/tree/bug/repro-dupe-listen-max-call-stack. See the tiny diff of changes required to repro the error here: libp2p/js-libp2p-examples@8abf359

Steps to reproduce:

git clone https://github.com/SgtPooki/js-libp2p-examples.git
cd js-libp2p-examples
git checkout bug/repro-dupe-listen-max-call-stack
npm i
node src/listener.js
@SgtPooki SgtPooki added the need/triage Needs initial labeling and prioritization label May 10, 2024
@SgtPooki
Copy link
Member Author

SgtPooki commented May 10, 2024

I also ran ncu '*libp2p*' -u to update all libp2p deps and it's also reproducible on latest:

 @chainsafe/libp2p-noise  ^14.0.0  →  ^15.0.0
 @chainsafe/libp2p-yamux   ^6.0.1  →   ^6.0.2
 @libp2p/peer-id-factory   ^4.0.0  →   ^4.1.1
 @libp2p/tcp               ^9.0.4  →  ^9.0.24
 @libp2p/websockets        ^8.0.4  →  ^8.0.22
 libp2p                    ^1.0.8  →   ^1.5.1

this was pushed to repro branch with libp2p/js-libp2p-examples@6b459f6

@dhuseby dhuseby moved this to 🤨Needs Investigation in js-libp2p May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
Status: 🤨Needs Investigation
Development

No branches or pull requests

1 participant