Skip to content

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

Closed
@SgtPooki

Description

@SgtPooki
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    Status

    🎉Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions