Open elderapo opened 3 years ago
Actually, I think the issue is not with this library but with bchd.fountainhead.cash:443
. Seems like it's behind some reverse proxy that timeouts after 10 minutes.
Correct, it times out after 10 minutes of no activity, you need to create a self-healing stream like this:
Hmm... Reconnecting on disconnect seems like a good idea but for some reason my stream never "emits" any events besides data
:
transactionsStream.on("close", () => console.log("close"));
transactionsStream.on("data", () => console.log("data"));
transactionsStream.on("end", () => console.log("end"));
transactionsStream.on("error", () => console.log("error"));
transactionsStream.on("pause", () => console.log("pause"));
In my test, I set up a transactions stream, waited for some data
events, disconnected wifi from my laptop, reconnected wifi. I expected to get either close
or end
events but they never got emitted :thinking:
What happens if you apply this patch:
index f971817..ec22ace 100644
--- a/src/client.ts
+++ b/src/client.ts
@@ -364,7 +364,7 @@ export class GrpcClient {
req.setSubscribe(filter);
try {
- resolve(this.client.subscribeTransactions(req));
+ resolve(this.client.subscribeTransactionStream(req));
} catch (err) {
reject(err);
}
@@ -386,7 +386,7 @@ export class GrpcClient {
includeTxnData ? req.setFullTransactions(true) : req.setFullTransactions(false);
includeSerializedBlock ? req.setSerializeBlock(true) : req.setSerializeBlock(false);
try {
- resolve(this.client.subscribeBlocks(req));
+ resolve(this.client.subscribeTransactionStream(req));
} catch (err) {
reject(err);
}
After switching from subscribeTransactions
to subscribeTransactionStream
I no longer get any events (not even data
ones).
Is it working for you?
I haven't tried the patch, I just saw that it was an alternative in the bchrpc.proto file so thought it would be work the try. We may need to search on some gRPC related topics in order to get to the bottom of the issue. I'm not able to look into it at the moment.
I've found a funny workaround. After creating a client I instantly start listening for txs, and if there is no tx notification in x seconds I treat that client as "disconnected". It causes my container to become unhealthy and it gets restarted :)
Basically what the title says... This is the error: