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

Added host monitor thread to disconnect offline PoE devices #509

Merged
merged 1 commit into from
Jul 4, 2022

Conversation

themarpe
Copy link
Collaborator

Creates a watchdog triggered disconnect from PoE device which have gone offline.
Also addresses: #476

@themarpe
Copy link
Collaborator Author

Details are layed out in #476 and in referenced: #366 (comment)

Scenario happened as:

Stack trace

depthai.cpython-38-x86_64-linux-gnu.so!__gnu_cxx::__atomic_add(volatile _Atomic_word * __mem, int __val) (/usr/include/c++/10/ext/atomicity.h:55)
depthai.cpython-38-x86_64-linux-gnu.so!__gnu_cxx::__atomic_add_dispatch(_Atomic_word * __mem, int __val) (/usr/include/c++/10/ext/atomicity.h:96)
depthai.cpython-38-x86_64-linux-gnu.so!std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_copy(std::_Sp_counted_base<__gnu_cxx::_S_atomic> * this) (/usr/include/c++/10/bits/shared_ptr_base.h:142)
depthai.cpython-38-x86_64-linux-gnu.so!std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__shared_count<__gnu_cxx::_S_atomic> * this, const std::__shared_count<__gnu_cxx::_S_atomic> & __r) (/usr/include/c++/10/bits/shared_ptr_base.h:740)
depthai.cpython-38-x86_64-linux-gnu.so!std::__shared_ptr<dai::ADatatype, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<dai::ADatatype>(std::__shared_ptr<dai::ADatatype, __gnu_cxx::_S_atomic> * this, const std::__shared_ptr<dai::ADatatype, __gnu_cxx::_S_atomic> & __r, std::__shared_ptr<dai::ADatatype, __gnu_cxx::_S_atomic>::element_type * __p) (/usr/include/c++/10/bits/shared_ptr_base.h:1168)
depthai.cpython-38-x86_64-linux-gnu.so!std::shared_ptr<dai::ADatatype>::shared_ptr<dai::ADatatype>(std::shared_ptr<dai::ADatatype> * this, const std::shared_ptr<dai::ADatatype> & __r, std::shared_ptr<dai::ADatatype>::element_type * __p) (/usr/include/c++/10/bits/shared_ptr.h:257)
depthai.cpython-38-x86_64-linux-gnu.so!std::dynamic_pointer_cast<dai::ADatatype, dai::ADatatype>(const std::shared_ptr<dai::ADatatype> & __r) (/usr/include/c++/10/bits/shared_ptr.h:603)
depthai.cpython-38-x86_64-linux-gnu.so!dai::DataOutputQueue::get<dai::ADatatype, long, std::ratio<1l, 1000l> >(dai::DataOutputQueue * this, std::chrono::duration<long, std::ratio<1, 1000> > timeout, bool & hasTimedout) (depthai-python/depthai-core/include/depthai/device/DataQueue.hpp:227)
depthai.cpython-38-x86_64-linux-gnu.so!dai::DataOutputQueue::get<long, std::ratio<1l, 1000l> >(dai::DataOutputQueue * this, std::chrono::duration<long, std::ratio<1, 1000> > timeout, bool & hasTimedout) (depthai-python/depthai-core/include/depthai/device/DataQueue.hpp:239)
depthai.cpython-38-x86_64-linux-gnu.so!DataQueueBindings::bind(pybind11::module_&, void*)::$_2::operator()(dai::DataOutputQueue&) const(const class {...} * this, dai::DataOutputQueue & obj) (depthai-python/src/DataQueueBindings.cpp:97)
depthai.cpython-38-x86_64-linux-gnu.so!pybind11::detail::argument_loader<dai::DataOutputQueue&>::call_impl<std::shared_ptr<dai::ADatatype>, DataQueueBindings::bind(pybind11::module_&, void*)::$_2&, 0ul, pybind11::detail::void_type>(DataQueueBindings::bind(pybind11::module_&, void*)::$_2&, std::integer_sequence<unsigned long, 0ul>, pybind11::detail::void_type&&) &&(pybind11::detail::argument_loader<dai::DataOutputQueue&> * this, class {...} & f) (/home/themarpe/.hunter/_Base/cb0ea1f/84bd56f/1c0de32/Install/include/pybind11/cast.h:1441)
depthai.cpython-38-x86_64-linux-gnu.so!pybind11::detail::argument_loader<dai::DataOutputQueue&>::call<std::shared_ptr<dai::ADatatype>, pybind11::detail::void_type, DataQueueBindings::bind(pybind11::module_&, void*)::$_2&>(pybind11::detail::argument_loader<dai::DataOutputQueue&> * this, class {...} & f) (/home/themarpe/.hunter/_Base/cb0ea1f/84bd56f/1c0de32/Install/include/pybind11/cast.h:1409)
depthai.cpython-38-x86_64-linux-gnu.so!pybind11::cpp_function::initialize<DataQueueBindings::bind(pybind11::module_&, void*)::$_2, std::shared_ptr<dai::ADatatype>, dai::DataOutputQueue&, pybind11::name, pybind11::is_method, pybind11::sibling, char const*>(DataQueueBindings::bind(pybind11::module_&, void*)::$_2&&, std::shared_ptr<dai::ADatatype> (*)(dai::DataOutputQueue&), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&, char const* const&)::{lambda(pybind11::detail::function_call&)#1}::operator()(pybind11::detail::function_call&) const(const class {...} * this, pybind11::detail::function_call & call) (/home/themarpe/.hunter/_Base/cb0ea1f/84bd56f/1c0de32/Install/include/pybind11/pybind11.h:249)
depthai.cpython-38-x86_64-linux-gnu.so!pybind11::cpp_function::initialize<DataQueueBindings::bind(pybind11::module_&, void*)::$_2, std::shared_ptr<dai::ADatatype>, dai::DataOutputQueue&, pybind11::name, pybind11::is_method, pybind11::sibling, char const*>(DataQueueBindings::bind(pybind11::module_&, void*)::$_2&&, std::shared_ptr<dai::ADatatype> (*)(dai::DataOutputQueue&), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&, char const* const&)::{lambda(pybind11::detail::function_call&)#1}::__invoke(pybind11::detail::function_call&)(pybind11::detail::function_call & call) (/home/themarpe/.hunter/_Base/cb0ea1f/84bd56f/1c0de32/Install/include/pybind11/pybind11.h:224)
depthai.cpython-38-x86_64-linux-gnu.so!pybind11::cpp_function::dispatcher(PyObject * self, PyObject * args_in, PyObject * kwargs_in) (/home/themarpe/.hunter/_Base/cb0ea1f/84bd56f/1c0de32/Install/include/pybind11/pybind11.h:934)
PyCFunction_Call (Unknown Source:0)
_PyObject_MakeTpCall (Unknown Source:0)
[Unknown/Just-In-Time compiled code] (Unknown Source:0)
_PyEval_EvalFrameDefault (Unknown Source:0)
_PyEval_EvalCodeWithName (Unknown Source:0)

Code in question

    template <class T, typename Rep, typename Period>
    std::shared_ptr<T> get(std::chrono::duration<Rep, Period> timeout, bool& hasTimedout) {
        if(!running) throw std::runtime_error(exceptionMessage.c_str());
        std::shared_ptr<ADatatype> val = nullptr;
        if(!queue.tryWaitAndPop(val, timeout)) {
            hasTimedout = true;
            return nullptr;
        }
        hasTimedout = false;
        return std::dynamic_pointer_cast<T>(val); # <- Segfault - val is uninitialized (garbage value)
    }

Adding proper destructed checks and guarding those under same mutex as the rest of the LockingQueue share, should create the correct flow for cases where a queue is destructed in between messages being actively pushed into it.

@themarpe themarpe merged commit 9a824cd into develop Jul 4, 2022
@themarpe themarpe deleted the host_monitor_thread branch July 4, 2022 19:33
This was referenced Jul 11, 2022
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

Successfully merging this pull request may close these issues.

3 participants