Skip to content

Fall back to IPv4 when IPv6 dual-stack bind fails in discovery#1724

Open
stiefenm wants to merge 1 commit into
librespot-org:devfrom
stiefenm:fix-ipv6-discovery-fallback
Open

Fall back to IPv4 when IPv6 dual-stack bind fails in discovery#1724
stiefenm wants to merge 1 commit into
librespot-org:devfrom
stiefenm:fix-ipv6-discovery-fallback

Conversation

@stiefenm

Copy link
Copy Markdown

Summary

  • Fall back to 0.0.0.0:port (IPv4-only) when the [::]:port (IPv6 dual-stack) bind fails on non-Windows systems

On systems where IPv6 is completely disabled at the kernel level (e.g. ipv6.disable=1 on Raspberry Pi / piCorePlayer), TcpListener::bind("[::]:port") fails with EAFNOSUPPORT (os error 97), preventing the discovery server from starting entirely. This makes librespot invisible to the Spotify app on those hosts.

The fix tries the dual-stack bind first (preserving existing behavior on normal systems), and only falls back to IPv4 if it fails. The Windows path is unaffected (it already binds to 0.0.0.0).

Tested

Running this patch in production via SpotOn (an LMS Spotify plugin using librespot) on both dual-stack and IPv4-only systems. Multiple users on piCorePlayer / Raspberry Pi have confirmed discovery works with ipv6.disable=1 after this change.

Fixes #1694

On systems where IPv6 is completely disabled at the kernel level
(e.g. `ipv6.disable=1` on Raspberry Pi / piCorePlayer), the
dual-stack bind to `[::]:port` fails with EAFNOSUPPORT (os error 97),
preventing the discovery server from starting entirely.

Fall back to binding `0.0.0.0:port` (IPv4-only) when the dual-stack
bind fails on non-Windows systems. This preserves dual-stack behavior
on normal systems while allowing discovery to work on IPv4-only hosts.

Fixes librespot-org#1694
@stiefenm

Copy link
Copy Markdown
Author

CI clippy failure is a pre-existing issue in metadata/src/audio/item.rs:197 (unrelated to this PR) — the newer Rust 1.96 clippy flags sort_bysort_by_key. This also fails on the dev branch itself. Happy to rebase once that's fixed upstream, or I can include the one-liner fix in this PR if preferred.

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.

Could not initialise discovery: Unknown error { Address family not supported by protocol (os error 97) }

1 participant