Open x48115 opened 1 year ago
This is interesting as I have in the past tried to re-used streams but failed to do so. I think I mainly experimented with store and not light push
while it shouldn't matter, but with js-libp2p example gossipsub is directly being used (no wait for ack), while lightpush uses req-res model (per stream) and requires to wait for ack.
if OP wants to parallelise and send multiple messages using lightpush over js-libp2p, configuring this options to increase max outbound streams should help: https://github.com/libp2p/js-libp2p/blob/5ffa7a74d5b972bdac387782d6010b6a19558600/packages/pubsub-gossipsub/src/stream.ts#L8 might help
we can't reuse streams with lightpush because each request is sent on one stream, and libp2p will close stream after a response is receieved.
@x48115 pls let us know if that helps. happy to keep this open until satisfaction is obtained.
To add on that, I have tried in the past to re-use the same stream on req-resp protocols such as store but libp2p closes the stream once the response is received. Maybe it's something that changed.
Also note that if you send several messages on the outbound stream with light push, you will expect several responses (for the ack). The whole point of being able to create several stream is this exact multiplexing need AFAIK.
As mentioned above, you should be able to pass libp2p options to createLightNode
to increase the number of streams (maxOutboundStreams
).
Moving to Triage to discuss any potential work which might include graceful handling of sending multiple requests at once. Potentially can be perceived as part of https://github.com/waku-org/js-waku/issues/2154
Let's check:
js-waku
has - how many messages per second etc;RLN
limit interferes with amount of messages being send (should we throw if it is higher than RLN
limit);lightPush
;Additional action point: if increase to outbound streams influence it anyhow. This issue does not improve reliability
.
Problem
When attempting to send many messages back to back we run into an error:
ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS
Steps to reproduce
Expected Results
Expected to be able to send many messages back to back with no error (I can do this with libp2p directly with both floodsub and gossipsub implementations
Actual results
Libp2p example with no issues
Note
This is mentioned in a couple places: https://github.com/ChainSafe/js-libp2p-gossipsub/issues/306 https://github.com/ChainSafe/js-libp2p-gossipsub/pull/293
Suggested fix
Currently
lightPush.send
makes a new stream for every method. In the comments in the two issues above it seems js-libp2p's expectation is that a protocol should only have one open stream and send all messages over that stream instead of opening a new stream per message.https://github.com/waku-org/js-waku/blob/89392dbfdf5471e540ec563980f34ecbfcc9981f/packages/core/src/lib/light_push/index.ts#L49