Ableton / link

Ableton Link
Other
1.06k stars 145 forks source link

Disabling Link causes ESP32 watchdog errors #122

Closed vizzie closed 9 months ago

vizzie commented 1 year ago

I have a feature request to disable Link in my ESP32 project. When I set link.enable(false) during runtime I start getting watchdog errors and ASIO error messages such as these:

0x40107b16: asio::detail::scheduler::poll_one(std::error_code&) at ~/esp/esp-idf/components/asio/asio/asio/include/asio/detail/impl/scheduler.ipp:296

0x40107ba5: asio::io_context::poll_one() at ~/esp/esp-idf/components/asio/asio/asio/include/asio/impl/io_context.ipp:107

0x400ebd79: ableton::platforms::esp32::Context<ableton::platforms::esp32::ScanIpIfAddrs, ableton::util::NullLog>::ServiceRunner::run(void*) at ...build/../components/link_component/link/include/ableton/platforms/esp32/Context.hpp:52

I tried stopping my output processes, anything that might be using Link, and letting things settle before changing the link to disabled. The error messages start happening even before I re-start those tasks that use Link.

I also tried toggling Link in the simplified ESP32 example included in the Link examples repository. I get similar errors.

If I set Link.enable(false) on startup, the system is fine and behaves as if there are no link peers, as expected. No error messages at all. But if I toggle Link on and then off again, error messages.

Do you have any ideas why these errors are happening? At this point, I don't believe it is anything my code is doing... but perhaps I am not doing everything I should upon disabling Link?

vizzie commented 1 year ago

In order to reproduce this you must have other Link peers on the network when you disable link. If there are no Link peers, then disabling Link does not produce these messages and the system stays stable.

fgo-ableton commented 1 year ago

I looked into this. I can reproduce the issue. It seems it actually also happens without connecting to other peers. Calling enable(true/false) is all that should be necessary. When Link gets enabled it looks for network interfaces and creates sockets on the interfaces it finds. Those sockets get closed when Link gets disabled. When it gets enabled again, Link again scans for interfaces and sets up sockets. I'm not yet sure what underlying issue is, but the stack trace I get here hints at some issue when calling select on the sockets asio::detail::socket_ops::select. It might be possible to tweak the timer in include/ableton/platforms/esp32/Context.hpp somehow to prevent the timeouts. I'm not sure how atm...