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

Subscribe fails with Error subscribing to peer #1562

Closed
Tracked by #1455
agazso opened this issue Sep 11, 2023 · 4 comments
Closed
Tracked by #1455

Subscribe fails with Error subscribing to peer #1562

agazso opened this issue Sep 11, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@agazso
Copy link

agazso commented Sep 11, 2023

This is a bug report

Problem

I have an app and it subscribes to several topics when it starts. It usually works but sometimes it returns with this error:

Error subscribing to peer: 16Uiu2HAm8gXHntr3SB5sde11pavjptaoiqyvwoX3GyEZWKMPiuBu for content topics: /wakuobjects-playground/1/private-message/e8cb81467b1bf57d41970d3e87bd9138f4f6ed455fde9beb4acc18f89c46cd84: TypeError: Cannot read properties of undefined (reading 'slice')

(See full stack trace below). I am not sure how to deal with this. There were four subscriptions and three other subscribe calls were successful. I also print out the waku connection status and it was reported as connected at the time of the call, but 200 milliseconds later it got disconnected (as in it got peer:disconnected event from libp2p and libp2p.getConnections().length === 0).

Proposed Solutions

I think it would be better if the library checked for the value before trying to call slice on it. And if it is undefined then throw an exception which describes what happened or at least the documentation could include it along with some instructions what to do in that case (for example repeat the subscribe call or something).

Notes

@waku/sdk version 0.0.18
Running on Node v18.17 on Linux
Connected to nwaku 0.18

Full stack trace:

Error: Error subscribing to peer: 16Uiu2HAm8gXHntr3SB5sde11pavjptaoiqyvwoX3GyEZWKMPiuBu for content topics: /wakuobjects-playground/1/private-message/e8cb81467b1bf57d41970d3e87bd9138f4f6ed455fde9beb4acc18f89c46cd84: TypeError: Cannot read properties of undefined (reading 'slice')
    at Subscription.subscribe (/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@waku/core/src/lib/filter/index.ts:110:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Filter.subscribe (/home/attila/Projects/LogosLab/waku-objects-playground/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@waku/core/src/lib/filter/index.ts:309:5)
    at subscribe (/home/attila/Projects/LogosLab/waku-objects-playground/src/lib/adapters/waku/waku.ts:73:22)
    at main (/home/attila/Projects/LogosLab/waku-objects-playground/src/lib/adapters/waku/bot.ts:75:3)
@fryorcraken fryorcraken added this to Waku Sep 11, 2023
@weboko weboko self-assigned this Sep 11, 2023
@weboko
Copy link
Collaborator

weboko commented Sep 11, 2023

Thanks for the report! I will look into it along the other one.

@weboko
Copy link
Collaborator

weboko commented Sep 13, 2023

So, for now, adding error handling for that case to see what actually breaks.
Didn't manage to repro in any of our examples (with peers being dropped) so I guess this is some kind of bad timing that causes this particular problem.

@agazso could you share a minimal repro setup, please?

Once I understand I can add unit test for that case.

@weboko weboko mentioned this issue Sep 14, 2023
24 tasks
@agazso
Copy link
Author

agazso commented Sep 14, 2023

So, for now, adding error handling for that case to see what actually breaks. Didn't manage to repro in any of our examples (with peers being dropped) so I guess this is some kind of bad timing that causes this particular problem.

@agazso could you share a minimal repro setup, please?

Once I understand I can add unit test for that case.

I accidentally found a minimal reproduction by using waku.stop() which my code originally did not have, so that's not the only way to trigger the issue. I tested this with running nwaku version 0.20.0 locally with docker.

If the await unsubscribe() line is removed it triggers a similar error than in #1553

import { Protocols } from "@waku/interfaces"
import { createDecoder, createLightNode, waitForRemotePeer } from "@waku/sdk"
import { multiaddr } from '@multiformats/multiaddr'

// change the id of the peer
const peerMultiaddr = multiaddr(
	'/ip4/127.0.0.1/tcp/8000/ws/p2p/16Uiu2HAm53sojJN72rFbYg6GV2LpRRER9XeWkiEAhjKy3aL9cN5Z',
)

main()

async function main() {
    const waku = await createLightNode()    
    await waku.start()
    await waku.dial(peerMultiaddr)
    await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush, Protocols.Store])

    const messageDecoder = createDecoder('abc')
    const unsubscribe = await waku.filter.subscribe([messageDecoder], () => { /* */ })

    await unsubscribe()

    await waku.stop()
}

@weboko
Copy link
Collaborator

weboko commented Sep 25, 2023

My guess now is that recent changes fix the problem and currently it fails on .dial call so should be possible to catch such an issue.

@weboko weboko closed this as completed Sep 25, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Waku Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants