Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribing to an already subscribed topic will result in crash #20

Closed
shekharhimanshu opened this issue Jun 21, 2017 · 2 comments
Closed

Comments

@shekharhimanshu
Copy link
Contributor

shekharhimanshu commented Jun 21, 2017

Hello,

In one of my tests, subscribing to an already subscribed topic results in crash inside the SDK. Here is the test sequence:

1. connect
2. subscribe to a topic, TopicA
3. disconnect
4. connect
5. subscribe again to TopicA ------> CRASH!!

I found the code causing the crash to be below in Subscribe.cpp:

ResponseCode SubscribeActionAsync::PerformAction(std::shared_ptr<NetworkConnection> p_network_connection, std::shared_ptr<ActionData> p_action_data) {

....

// Read running in separate thread, Insert before sending request to avoid situations where response arrives early
            util::Vector<std::shared_ptr<Subscription>>::iterator itr = p_subscribe_packet->subscription_list_.begin();
            while (itr != p_subscribe_packet->subscription_list_.end()) {
                util::String topic_name = (*itr)->GetTopicName()->ToStdString();
                auto existing_itr = p_client_state_->subscription_map_.find(topic_name);
                if (p_client_state_->subscription_map_.end() != existing_itr) {
                    if (existing_itr->second->IsActive()) {
                        itr = p_subscribe_packet->subscription_list_.erase(itr);
                    }
                } else {
                    p_client_state_->subscription_map_.insert(std::make_pair(topic_name, (*itr)));
                }

                itr++;
            }
...

I think when subscribing to an already subscribed topic, the code is erasing an element from p_subscribe_packet->subscription_list_ vector here while iterating the same and advancing the iterator afterwards here which causes the crash.

I would be happy to submit a fix.

@vareddy-zz
Copy link
Contributor

Hi @shekharhimanshu,
I'm able to reproduce it and I've added it into our backlog for the next release. If you have a fix, could you please submit a pull request? It would be good to compare all approaches to the issue.
Thanks a lot for your help!
Varun

@vareddy-zz
Copy link
Contributor

Hi @shekharhimanshu,
This issue is fixed as a part of the subscription cleanup in v1.1.1.
Thanks!
Varun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants