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

[Pubsub] Cannot read property 'catch' of undefined in pubsub.attachConnection #694

Closed
geolffreym opened this issue Jul 7, 2020 · 9 comments
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@geolffreym
Copy link

geolffreym commented Jul 7, 2020

when a peer is connected a get this :( something happen with webrtc-star using ipfs@0.46.0

my conf!!

module.exports = (opts) => {
	// Set convenience variables to clearly showcase some of the useful things that are available
	// const peerId = opts.peerId;
	
	opts.libp2pOptions.modules.peerDiscovery = [Bootstrap];
	opts.libp2pOptions.modules.transport.push(WebrtcStar);
	opts.libp2pOptions.config.transport = {
		[WebrtcStar.prototype[Symbol.toStringTag]]: {
			wrtc
		}
	}
	
	// Build and return our libp2p node
	return new Libp2p(opts.libp2pOptions)
}

peerInfo.protocols.forEach((p) => newPeerInfo.protocols.add(p))

TypeError: Cannot read property 'forEach' of undefined
    at PeerStore.add (/node_modules/libp2p/src/peer-store/index.js:83:24)
    at PeerStore.put (/node_modules/libp2p/src/peer-store/index.js:61:19)
    at Libp2p._onDiscoveryPeer (/node_modules/libp2p/src/index.js:443:20)
    at EventEmitter.emit (events.js:315:20)
    at ClassIsWrapper._peerDiscovered (/node_modules/libp2p-webrtc-star/src/index.js:237:20)
    at Socket.Emitter.emit (/node_modules/component-emitter/index.js:133:20)
    at Socket.onevent (/socket.io-client/lib/socket.js:278:10)
    at Socket.onpacket (/socket.io-client/lib/socket.js:236:12)
    at Manager.<anonymous> (/node_modules/component-bind/index.js:21:15)
    at Manager.Emitter.emit (/node_modules/component-emitter/index.js:133:20)

CC @jacobheun @vasco-santos

@vasco-santos
Copy link
Member

@geolffreym
you need to bump the webrtc-star in this case. You can see what dependencies you need to bump here https://github.com/libp2p/js-libp2p/pull/649/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R101.

I will make sure this gets more visible for people migrating

@geolffreym
Copy link
Author

geolffreym commented Jul 7, 2020

So, i need use ipfs@0.46 how can i just fix this peer-store issue? upgrading to js-ipfs@0.28 or just adding the the new packages? @vasco-santos

Currently i am using this:

    "ipfs": "^0.46.0",
    "ipfs-http-client": "^44.3.0",
    "it-last": "^1.0.2",
    "libp2p-webrtc-star": "^0.18.6",

tried installing:

"libp2p-bootstrap": "^0.11.0",
"libp2p-delegated-content-routing": "^0.5.0",
"libp2p-delegated-peer-routing": "^0.5.0",
"libp2p-floodsub": "^0.21.0",
"libp2p-gossipsub": "^0.4.0",
"libp2p-kad-dht": "^0.19.1",
"libp2p-mdns": "^0.14.1",
"libp2p-webrtc-star": "^0.18.0"

same result CC @jacobheun

@geolffreym
Copy link
Author

geolffreym commented Jul 7, 2020

i think the issue is because i have installed
"libp2p-webrtc-star": "^0.18.0" with ipfs@0.46.0 which uses libp2p-webrtc-star": "^0.17.9..
it can be that? @vasco-santos

@vasco-santos
Copy link
Member

vasco-santos commented Jul 8, 2020

Yes, ipfs@0.46.0 uses libp2p@0.27 which is compatible with libp2p-webrtc-start@0.17.x.

Also, if you want to use ipfs@0.46.0, you need to go back with the other modules update. TLDR: this was the breaking change for the modules update: #589

@geolffreym
Copy link
Author

geolffreym commented Jul 8, 2020

installed

"ipfs": "^0.46.0",
"it-last": "^1.0.2",
"libp2p-bootstrap": "^0.11.0",
"libp2p-delegated-content-routing": "^0.5.0",
"libp2p-delegated-peer-routing": "^0.5.0",
"libp2p-floodsub": "^0.21.0",
"libp2p-gossipsub": "^0.4.0",
"libp2p-webrtc-star": "^0.18.0",
"mongodb": "^3.5.7",
"node-rsa": "^1.0.8",
"orbit-db": "~0.24.2",
"wrtc": "^0.4.5"

https://github.com/libp2p/js-libp2p/blob/master/doc/migrations/v0.27-v.28.md

In this approach catch thows error... async/await UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'catch' of undefined think is related to it-pipe

libp2p-pubsub@0.4.7

    pipe(
      this.stream,
      lp.encode(),
      conn
    ).catch(err => { <----
      log.error(err)
    })
Promise { <pending> }
Promise { <pending> }
Promise { <pending> }
Promise { undefined } <-----
Promise { <pending> }
Promise { <pending> }
Promise { <pending> }
Promise { undefined }
Promise { <pending> }

debugging

const rawPipe = (...fns) => {
	let res
	while (fns.length) {
		let sh = fns.shift()
		console.log(res);
		res = sh(res)
	}
	return res || Promise.resolve('test') <- my hot fix!! i think should somehing better right?
}

log return result

Object [AsyncGenerator] {}
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Promise { undefined } <---------------- HERE
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
Promise { <pending> }
Object [AsyncGenerator] {
  push: [Function: push],
  end: [Function: end],
  return: [Function: return]
}
Promise { undefined } <-------------- HERE
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
Loading db..
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
[
  <Buffer 2a 0a 69 70 66 73 2f 30 2e 31 2e 30 32 0f 6a 73 2d 6c 69 62 70 32 70 2f 30 2e 31 2e 30 0a ab 02 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 ... 642 more bytes>
]
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Promise { <pending> }
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
[]
[]
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Promise { <pending> }
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Object [AsyncGenerator] {}
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Promise { <pending> }
{
  next: [Function: next],
  throw: [Function: throw],
  return: [Function: return],
  push: [Function: push],
  end: [Function: end],
  [Symbol(Symbol.asyncIterator)]: [Function: [Symbol.asyncIterator]]
}
Object [AsyncGenerator] {}
Object [AsyncGenerator] {}
{
  next: [Function (anonymous)],
  throw: [Function (anonymous)],
  return: [Function (anonymous)],
  [Symbol(Symbol.asyncIterator)]: [Function (anonymous)]
}
Promise { <pending> }
undefined <-------------- HERE
 

@vasco-santos @jacobheun

@jacobheun
Copy link
Contributor

ipfs@0.46 doesn't support libp2p 0.28, just 0.27. The modules you have installed aren't compatible, which is likely causing this issue. Can you try installing the previous minors of these modules:

"libp2p-bootstrap": "^0.10.0",
"libp2p-delegated-content-routing": "^0.4.0",
"libp2p-delegated-peer-routing": "^0.4.0",
"libp2p-floodsub": "^0.20.0",
"libp2p-gossipsub": "^0.3.0",
"libp2p-webrtc-star": "^0.17.0"

We need to add peerDependency versions for libp2p on all the modules to help prevent incompatible installations.

@geolffreym
Copy link
Author

geolffreym commented Jul 8, 2020

@jacobheun

    "hash-generator": "^0.1.0",
    "ipfs": "^0.46.0",
    "libp2p-bootstrap": "^0.10.0",
    "libp2p-delegated-content-routing": "^0.4.0",
    "libp2p-delegated-peer-routing": "^0.4.0",
    "libp2p-floodsub": "^0.20.0",
    "libp2p-gossipsub": "^0.3.0",
    "libp2p-webrtc-star": "^0.17.0",
(node:11843) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'catch' of undefined
    at Peer.attachConnection (/node_modules/libp2p-pubsub/src/peer.js:107:6)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:11843) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4518)

This is not killing the process at all.. is just jumping like crazy in my console!! i am trying right now!!! thanks

@jacobheun
Copy link
Contributor

Is that happening when the node is idle? It's odd that pipe is returning undefined

@jacobheun jacobheun added the kind/bug A bug in existing code (including security flaws) label Jul 8, 2020
@jacobheun jacobheun changed the title Cannot read property 'forEach' of undefined [Pubsub] Cannot read property 'catch' of undefined in pubsub.attachConnection Jul 8, 2020
@jacobheun
Copy link
Contributor

jacobheun commented Jul 13, 2020

The underlying issue was fixed in 0.28.3 but was not back ported to 0.27.x. You can now install 0.27.9 which includes the back ported patch.

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)
Projects
None yet
Development

No branches or pull requests

3 participants