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

Stack overflow on the erase_resource of a resource joined with it's sub-resources #403

Open
mgirard1mtx opened this issue Aug 7, 2024 · 3 comments

Comments

@mgirard1mtx
Copy link

If a resource is within its subresource there is not limit on recursion:

for (auto& sub_resource : found->sub_resources)
{
count += erase_resource(resources, sub_resource, forget_now);
}

Suggested patch:

            const auto sid = utility::us2s(id);
[...]
            for (auto& sub_resource : found->sub_resources)
            {
                if (sub_resource != sid)
                {
                    count += erase_resource(resources, sub_resource, forget_now);
                }
            }

Before the sugegsted patch stack is filled with (notice the same resource is erased recursively):

    [...]
    frame #58169: 0x00007ffa38c28f1d libmatrox_ipmx_c_api.so`nmos::erase_resource(resources=0x00007ff9bc0050e8, id="6a148326-c4f9-4a26-89b1-31083e516c60", forget_now=true)>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::tag<nmos::tags::type, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::composite_key<nmos::resource, boost::multi_index::const_mem_fun<nmos::resource, bool, &(nmos::resource::has_data() const)>, boost::multi_index::member<nmos::resource, nmos::type, &(nmos::resource::type)>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::created, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::created)>, std::greater<nmos::tai> >, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::updated, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::updated)>, std::greater<nmos::tai> >, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<nmos::resource> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) at resources.cpp:150:40
    frame #58170: 0x00007ffa38c28f1d libmatrox_ipmx_c_api.so`nmos::erase_resource(resources=0x00007ff9bc0050e8, id="6a148326-c4f9-4a26-89b1-31083e516c60", forget_now=true)>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::tag<nmos::tags::type, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::composite_key<nmos::resource, boost::multi_index::const_mem_fun<nmos::resource, bool, &(nmos::resource::has_data() const)>, boost::multi_index::member<nmos::resource, nmos::type, &(nmos::resource::type)>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::created, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::created)>, std::greater<nmos::tai> >, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::updated, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::updated)>, std::greater<nmos::tai> >, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<nmos::resource> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) at resources.cpp:150:40
    frame #58171: 0x00007ffa38c28f1d libmatrox_ipmx_c_api.so`nmos::erase_resource(resources=0x00007ff9bc0050e8, id="6a148326-c4f9-4a26-89b1-31083e516c60", forget_now=true)>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::tag<nmos::tags::type, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::composite_key<nmos::resource, boost::multi_index::const_mem_fun<nmos::resource, bool, &(nmos::resource::has_data() const)>, boost::multi_index::member<nmos::resource, nmos::type, &(nmos::resource::type)>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::created, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::created)>, std::greater<nmos::tai> >, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::updated, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::updated)>, std::greater<nmos::tai> >, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<nmos::resource> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) at resources.cpp:150:40
    frame #58172: 0x00007ffa38c28f1d libmatrox_ipmx_c_api.so`nmos::erase_resource(resources=0x00007ff9bc0050e8, id="6a148326-c4f9-4a26-89b1-31083e516c60", forget_now=true)>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::tag<nmos::tags::type, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::composite_key<nmos::resource, boost::multi_index::const_mem_fun<nmos::resource, bool, &(nmos::resource::has_data() const)>, boost::multi_index::member<nmos::resource, nmos::type, &(nmos::resource::type)>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::created, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::created)>, std::greater<nmos::tai> >, boost::multi_index::ordered_unique<boost::multi_index::tag<nmos::tags::updated, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<nmos::resource, nmos::tai, &(nmos::resource::updated)>, std::greater<nmos::tai> >, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<nmos::resource> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) at resources.cpp:150:40
    [...]
@garethsb
Copy link
Contributor

garethsb commented Aug 8, 2024

There is no valid reason for a resource to be listed as a sub-resource of itself. How did this situation occur?

Of course, still worth preventing the recursion. However, a fix should probably handle a resource being listed not just as its own sub-resource but also as a sub-resource of one of those resources, etc.

@mgirard1mtx
Copy link
Author

It seems I had by mistake the same device id and node id.

There seems to be missing code to prevent that setup and the erase_resource causes the stack overflow while doing the cleanup.

@garethsb
Copy link
Contributor

Thanks very much for confirming. I agree duplicate id could be prevented by nmos-cpp model itself or its free functions, need to think about most performant way to achieve this protection.

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