fix: TopicMessageQuery#unsubscribe() attempts to re-subscribe
🆕🐥 First Timers Only
This issue is reserved for people who have never contributed to Hedera or any open source project in general. We know that creating a pull request (PR) is a major barrier for new contributors. The goal of this issue and all other issues labeled by 'good first issue' is to help you make your first contribution to Hedera.
👾 Description of the issue
Problem
When using TopicMessageQuery to subscribe to a topic and then attempting to unsubscribe, an error is thrown that suggests the system is trying to re-subscribe rather than cleanly disconnect:
const subscription = new TopicMessageQuery()
.setTopicId(topicId)
.subscribe(client, myCallback);
subscription.unsubscribe();
This results in the following error:
Error subscribing to topic 0.0.3745107 during attempt 0. Waiting 250 ms before next attempt: 1 CANCELLED: Cancelled on client
The expected behavior is that unsubscribe() should terminate the subscription without attempting a re-subscription. This error likely affects users working on subscribing to topics in the Hedera network and needs a fix to ensure proper subscription management.
Steps to reproduce
- Set up this project
- Execute the script provided in the repo, located at: checkpoint-subscribe.js.
Expected Behavior
unsubscribe() should end the subscription without attempting any further reconnection attempts or retries.
Additional context
- Relevant discussion can be found in the Slack thread: TopicMessageQuery Conversation
Hedera network
testnet
Version
2.42.0
Operating system
macOS
📋 Step by step guide to do a contribution
If you have never contributed to an open source project at GitHub, the following step-by-step guide will introduce you to the workflow. More information and concrete samples for shell commands for each step can be found in our CONTRIBUTING.md file. A more detailed general documentation of the GitHub PR workflow can be found here.
- [ ] Claim this issue: Comment below that you are interested in working on the issue
- [ ] Wait for assignment: A community member with the given rights will add you as an assignee of the issue
- [ ] Fork the repository: You can do that in GitHub (by simply clicking the 'fork' button).
- [ ] Check out the forked repository
- [ ] Create a feature branch for the issue. We do not have a hard naming definition for branches but it is best practice to prefix the branch name with the issue id.
- [ ] Solve the issue in your branch.
- [ ] Commit your changes: Here, it is needed to add
sign-offinformation to the commit to accept the "Developer Certificate of Origin" (https://developercertificate.org). More details can be found in our CONTRIBUTING.md - [ ] Start a Pull Request (PR): We have a pattern for naming pull requests that a GitHub Action checks. We use that pattern to support the creation of automatic release notes.
- [ ] Check GitHub Actions: Several GitHub Actions will be triggered automatically for each PR. If a GitHub Action fails and you do not understand the cause of that error do not hesitate to add a comment to the PR and ask the Hedera developer community for support.
- [ ] Wait for reviews: Members of the Hedera developer community will review your PR. If a reviewer finds any missing pieces or a problem, he or she will start a discussion with you and describe the next steps for solving the problem.
- [ ] You did it 🎉: We will merge the fix in the develop branch. Thanks for being part of the Hedera community as an open-source contributor ❤️
🎉 Contribute to Hacktoberfest
Solve this issue as part of the Hacktoberfest event and get a chance to receive cool goodies like a T-Shirt. 🎽
🤔 Additional Information
If you have any questions, just ask us directly in this issue by adding a comment. You can join our community chat at Discord. A general manual about open-source contributions can be found here.
Hey @bguiz, the link to file checkpoint-subscribe.js is broken. Did you mean checkpoint-04-subscribe.js? Kindly update on how to replicate this issue
Can I work on this issue?
Can I work on this? I have never contributed to an open-source project before.
Hey @bguiz I would like to work on this issue
Hi @bguiz , @hendrikebbers , @agadzhalov and @ivaylogarnev-limechain I think to resolve this either adding timer to delay the sub procedure might work or manually stopping the process using onerror will work
If you find the approach correct or may have some suggestions for me please assign me this issue , I can work on it. Thankyou
Hey @hendrikebbers i have an update regarding the issue
i tested various scenarios and i think its working okay
this is the screenshot of the output the error due to continue subscribe process is not coming is there anything else to do? If not can i Give a PR Thankyou .
Hi @Manav958, in order to reproduce it, can you test this snippet against testnet, at the end you should receive
Error subscribing to topic 0.0.4963755 during attempt 0. Waiting 250 ms before next attempt: 1 CANCELLED: Cancelled on client
Hey @agadzhalov i tested the snippet and after 3 messages got sent it threw this error. what further steps should i take?
Hi @agadzhalov Please tell the necessary steps after the snippet test
Hi @Manav958, the expected result is to fix the bug by terminating the subscription and at the end the error should not be thrown. As a hint you can spend more time looking in the different Topic classes, also you can investigate the subscribe and unsubscribe methods.
The expected behavior is that unsubscribe() should terminate the subscription without attempting a re-subscription
Ok , I am improving on it
Hi all, @Manav958, thank you for the effort. I like how you ask questions. Go forward. @Jexsie, It Looks like you created a PR without being assigned to the issue. Please always make sure that you are assigned. Otherwise, two people will work on the issue.
I can not say if the PR by @Jexsie fixed the complete issue. Here I would like to hear @agadzhalov If it fixes all we will find a good other issue for @Manav958 Otherwise we can merge it and let @Manav958 do the rest of the work. By doing so you both did a PR :)
Thank you @hendrikebbers . If @Jexsie agrees we can work together on the issue , two better than one.
Hi @Manav958 @hendrikebbers. I've just tested @Jexsie's fix and seems to be working as expected. So may be @Manav958 can focus on some other good first issues