You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
Darwin MBP 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
Subsystem:
Pubsub
Severity:
Low
Description:
When you subscribe to a topic from a jsipfs API node, it is listed as a topic from the perspective of the client. I.e. pubsub.ls lists the topic as a subscription.
However, the topic is not registered on the client, and no pubsub messages are received by the client because it doesn't have a handler until a call to pubsub.subscribe is made.
As this is likely an edge case I don't think a code change is needed here (a warning would be nice though!) but some documentation could help.
Steps to reproduce the error:
Run a jsipfs node and subscribe to a topic
$ node api.js
// api.jsimportIPFSfrom'ipfs'importHttpApifrom'ipfs-http-server'consttopic='/ceramic/testnet-clay'asyncfunctionrun(){constipfs=awaitIPFS.create({libp2p: {config: {pubsub: {enabled: true}}}})awaitnewHttpApi(ipfs).start()console.log('IPFS API server listening on port 5011')try{awaitipfs.pubsub.subscribe(topic)console.log('subbed to topic',topic)}catch(error){console.log('sub failed',topic,error)}}run()
Run an http client script connected to the API
$ node client.js
// client.jsconstipfsClient=require("ipfs-http-client")consttopic=process.env.TOPIC||'/ceramic/testnet-clay'constipfsApiUrl=process.env.IPFS_API_URL||'http://localhost:5011'construn=async()=>{constipfs=ipfsClient({url: ipfsApiUrl})constreceiveMsg=(msg)=>{console.log('receiving',JSON.stringify(msg))}consttimeout=500resub()functionresub(){setInterval(async()=>{letsubbed=awaitsubbedAccordingToLs()if(subbed===true)console.log('ls says we are subscribed')subbed=awaitsubbedAccordingToSub()if(subbed===false)console.log('sub says we were not subscribed, but now we are')},5000)}asyncfunctionsubbedAccordingToLs(){letcurrentlySubbedawaitipfs.pubsub.ls({ timeout }).then((subs)=>{console.log('subs',subs)currentlySubbed=subs.includes(topic)}).catch((error)=>{console.error(error.message)currentlySubbed=undefined})returncurrentlySubbed}asyncfunctionsubbedAccordingToSub(){letalreadySubbedawaitipfs.pubsub.subscribe(topic,receiveMsg,{ timeout }).then(()=>{alreadySubbed=false}).catch((error)=>{if(error.message.includes('Already subscribed')){console.log(error.message)alreadySubbed=true}else{console.error(error.message)alreadySubbed=undefined}})returnalreadySubbed}}run()
Notice the output
$ node client.resub.js
subs [ '/ceramic/testnet-clay' ]
ls says we are subscribed
sub says we were not subscribed, but now we are
subs [ '/ceramic/testnet-clay' ]
ls says we are subscribed
Already subscribed to /ceramic/testnet-clay with this handler
The text was updated successfully, but these errors were encountered:
@valmack I see how this can be confusing, however I do not think there is an issue here. Client is just a remote controller of the node so ls returns all the topics that node is subscribed to regardless if they were established from this client or not. That is also why ls reports the topic that client has not subscribed to (node itself did).
Also note that first subscribe succeeds because receiveMsg handler is not registered yet, but fails in subsequent calls because it has been. If you were to use different handlers (e.g. inline function) every subscribe would have succeeded.
That said I understand this makes ls inadequate for detecting if client is subscribed to the topic. Maybe an argument could be made to add an option option to only list local subscriptions, but even that could be misleading as some other part of the program could have subscribed with a different handler. It is also worth considering if this would be necessary with proposed API #3465 (comment)
@valmack does this explanation makes sense ? And do we need to do something here ?
Http Client
Daemon
Darwin MBP 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
Pubsub
Severity:
Low
Description:
When you subscribe to a topic from a jsipfs API node, it is listed as a topic from the perspective of the client. I.e.
pubsub.ls
lists the topic as a subscription.However, the topic is not registered on the client, and no pubsub messages are received by the client because it doesn't have a handler until a call to
pubsub.subscribe
is made.As this is likely an edge case I don't think a code change is needed here (a warning would be nice though!) but some documentation could help.
Steps to reproduce the error:
The text was updated successfully, but these errors were encountered: