hedera-sdk-js icon indicating copy to clipboard operation
hedera-sdk-js copied to clipboard

fix: TopicMessageQuery#unsubscribe() attempts to re-subscribe

Open bguiz opened this issue 1 year ago • 14 comments

🆕🐥 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

  1. Set up this project
  2. 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

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-off information 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.

bguiz avatar Mar 26 '24 09:03 bguiz

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

Jexsie avatar Oct 05 '24 16:10 Jexsie

Can I work on this issue?

Atharva1723 avatar Oct 06 '24 10:10 Atharva1723

Can I work on this? I have never contributed to an open-source project before.

raymondjoseph02 avatar Oct 06 '24 11:10 raymondjoseph02

Hey @bguiz I would like to work on this issue

SIDHARTH20K4 avatar Oct 07 '24 00:10 SIDHARTH20K4

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

Manav958 avatar Oct 07 '24 18:10 Manav958

Hey @hendrikebbers i have an update regarding the issue

i tested various scenarios and i think its working okay Screenshot 2024-10-08 181209

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 .

Manav958 avatar Oct 08 '24 12:10 Manav958

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

agadzhalov avatar Oct 08 '24 14:10 agadzhalov

Hey @agadzhalov i tested the snippet and after 3 messages got sent it threw this error. what further steps should i take?

Manav958 avatar Oct 08 '24 17:10 Manav958

Hi @agadzhalov Please tell the necessary steps after the snippet test

Manav958 avatar Oct 09 '24 16:10 Manav958

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

agadzhalov avatar Oct 10 '24 12:10 agadzhalov

Ok , I am improving on it

Manav958 avatar Oct 11 '24 13:10 Manav958

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 :)

hendrikebbers avatar Oct 14 '24 07:10 hendrikebbers

Thank you @hendrikebbers . If @Jexsie agrees we can work together on the issue , two better than one.

Manav958 avatar Oct 14 '24 08:10 Manav958

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

agadzhalov avatar Oct 14 '24 09:10 agadzhalov