-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Cannot subscribe more than 5-6 topics [ipfs-http-client] #3741
Comments
Given it is not the same behaviour all the time, I would say the previous subscriptions are still being propagated in the network while the publish happens. When a pubsub subscription is done, it will take a bit before nodes exchange their subscription messages around. So, I suspect this is the problem. If so, we should improve our docs to make the expectations clear. @TheDiscordian could you wrap your bash script with an extra loop that sends the messages for the 20 topics multiple times to confirm these assumptions? |
Sure thing! I'll make it loop 20 times, with a delay between each attempt. |
@vasco-santos no change, still just first 5 subs using: #!/bin/bash
for ii in {1..20}
do
echo "BATCH "$ii
for i in {1..20}
do
ipfs pubsub pub $i $i
done
sleep 10
done FWIW I've never personally seen 6, I'm reporting 5-6 because the SO user reported 6 (here). It's possible they were mistaken. Edit: Log: https://ipfs.io/ipfs/QmdFNKLtp2RUheirioNFURfzRF9BwCbjM9Pf5T5c9Q3qgA |
Browsers can only have six concurrently open connections to a host name. Pubsub works over HTTP by holding a connection open per subscription, which means you can only subscribe six times before things start to hang. gRPC runs over websockets so doesn't have this limitation. This PR adds pubsub support to the gRPC server and `ipfs-client` module so you can subscribe to lots and lots of channels concurrently, working around the browser connection limitation. Refs: #3741
The problem here is that browsers limit the number of simultaneously open connections to a given hostname to six. In node you can increase this limit by configuring an agent for the http client to use but browsers are stuck with max six per hostname. Each subscription uses one connection so that's why you hit the limit. js-IPFS has an experimental gRPC-over-websockets server though, and it doesn't have this limitation. It only supports a few methods, the rest are all patched in by I've opened #3813 which implements |
Is this in the browser? Per the information, in the issue and stackoverflow this does not seem to be browser environment? |
In node the default agent used by the http client limits connections to 6 so it's consistent with the browser. You can configure your own agent to change this: const { create } = require('ipfs-http-client');
const http = require('http')
async function echo(msg) {
console.log(`TopicID: ${msg.topicIDs[0]}, Msg: ${new TextDecoder().decode(msg.data)}`);
}
async function run() {
// connect to the default API address http://localhost:5001
const client = create({
agent: http.Agent({ keepAlive: true, maxSockets: Infinity })
});
console.log(await client.version());
for (let i = 0; i < 20; i++) {
await client.pubsub.subscribe(parseInt(i), echo);
}
}
run();
|
* feat: pubsub over gRPC Browsers can only have six concurrently open connections to a host name. Pubsub works over HTTP by holding a connection open per subscription, which means you can only subscribe six times before things start to hang. gRPC runs over websockets so doesn't have this limitation. This PR adds pubsub support to the gRPC server and `ipfs-client` module so you can subscribe to lots and lots of channels concurrently, working around the browser connection limitation. Refs: #3741
This looks like it's been resolved, please re-open or create a new issue if you're still having problems. |
Platform:
Linux TheDesktop 5.10.42-1-MANJARO #1 SMP PREEMPT Thu Jun 3 14:37:11 UTC 2021 x86_64 GNU/Linux
Subsystem:
ipfs-http-client
Severity:
High
Description:
Issue found at: https://stackoverflow.com/questions/68257274/cannot-subscribe-to-more-than-6-ipfs-pubsub-channels-with-ipfs-http-client
Steps to reproduce the error:
First subscribe to the topics:
Then publish:
Output is only:
The text was updated successfully, but these errors were encountered: