Don't let a bad multicast interface abort (or terminate) stream resolution#283
Open
cboulay wants to merge 1 commit into
Open
Don't let a bad multicast interface abort (or terminate) stream resolution#283cboulay wants to merge 1 commit into
cboulay wants to merge 1 commit into
Conversation
The resolver selects the outbound interface for each multicast send via set_option(outbound_interface(...)) using the throwing overload. An interface that cannot be used for IP_MULTICAST_IF — a VPN utun, AWDL, a Hyper-V/VirtualBox adapter, or an address that changed since enumeration — makes this throw. Because it runs inside an asio completion handler the exception propagates out of io_->run(): in resolve_oneshot it aborts the wave and discards results already received, and in the continuous resolver the background thread has no try/catch, so it calls std::terminate() and takes the process down. This is the best code-level match for "plugging in a VPN / starting Docker breaks LSL discovery". - resolve_attempt_udp: use the error_code overload of set_option and, on failure, log and carry on. Multicast sends on that pass fall back to the socket's default interface, while the unicast and broadcast targets (which don't depend on the outbound interface) still go out. - resolver_impl: wrap the continuous resolver's background io->run() in the same catch-and-retry loop the outlet's IO threads already use, so any other stray handler exception can't terminate the process either. - test: lsl_test_resolve_bad_interface configures an unusable multicast interface (203.0.113.1, TEST-NET-3) and asserts the stream still resolves without crashing (pre-fix it throws out of resolve_oneshot). Co-authored-by: Wessel van Staal <w.vanstaal@eaglescience.nl>
abfcf5d to
99de309
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes stream resolution survive an unusable multicast interface instead of silently abandoning the resolve wave — or crashing the process. This is the best code-level match for "plugging in a VPN / starting Docker breaks LSL discovery."
Root cause
For each multicast send, the resolver selects the outbound interface via
multicast_socket_.set_option(outbound_interface(...))using the throwing overload (src/resolve_attempt_udp.cpp). An interface address that can't be used forIP_MULTICAST_IF— a VPNutun, AWDL, a Hyper-V/VirtualBox adapter, or an address that changed since enumeration — makes this throw. Because it runs inside an asio completion handler:resolve_oneshot, the exception propagates out ofio_->run(), aborting the wave and discarding results already received;io->run()with no try/catch, so the uncaught exception callsstd::terminate()and takes the process down.(The outlet's IO threads already have a catch-and-retry loop; the resolver's thread was just never given one.)
Fix
resolve_attempt_udp: use theerror_codeoverload ofset_optionand, on failure, log at verbosity 1 and carry on. Multicast sends on that pass fall back to the socket's default interface (and individually no-op on send error), while the unicast and broadcast targets — which don't depend on the outbound interface — still go out.resolver_impl: wrap the continuous resolver's backgroundio->run()in the same catch-and-retry loop the outlet's IO threads use, so any other stray handler exception can't terminate the process either.Test
New
lsl_test_resolve_bad_interface(own executable, since it sets theapi_configsingleton): configures an unusable multicast interface (203.0.113.1, TEST-NET-3 per RFC 5737) and asserts a local stream still resolves without crashing. Pre-fix it fails with "An internal error has occurred" (the asio exception thrown out ofresolve_oneshot); post-fix it passes.Testing
Full suite green locally (macOS universal): new test passes;
discovery,network,tcpserver, andruntime_configare unaffected.Scope / relationship