Skip to content

fix: send mDNS queries on multicast sockets#162

Open
Solaris-star wants to merge 2 commits into
hashicorp:mainfrom
Solaris-star:fix/144-multicast-query
Open

fix: send mDNS queries on multicast sockets#162
Solaris-star wants to merge 2 commits into
hashicorp:mainfrom
Solaris-star:fix/144-multicast-query

Conversation

@Solaris-star

@Solaris-star Solaris-star commented Jul 21, 2026

Copy link
Copy Markdown

Description

sendQuery sent mDNS queries to the multicast destination (224.0.0.251 / ff02::fb) only from unicast sockets. Some devices (e.g. Alfen EV Charger) only respond to queries that originate on a multicast socket (RFC 6762).

Fix

Also write queries via ipv4MulticastConn / ipv6MulticastConn, while keeping the existing unicast writes so local loopback discovery continues to work.

Tests

go test ./... -count=1

Passes on this machine (including TestServer_Lookup).

Linked Issue

Closes #144

@hashicorp-cla-app

hashicorp-cla-app Bot commented Jul 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

sendQuery only wrote to the multicast destination from unicast UDP
sockets. Some devices only answer queries that originate on a multicast
socket (RFC 6762).

Send via ipv4MulticastConn / ipv6MulticastConn as well, while keeping the
existing unicast writes so local loopback discovery tests still pass.

Fixes hashicorp#144
@tgross
tgross self-requested a review July 21, 2026 13:03

@tgross tgross left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You haven't added tests or even bothered explaining how you've confirmed that this change works manually.

Comment thread client.go Outdated
var last error
if c.ipv4MulticastConn != nil {
if _, err = c.ipv4MulticastConn.WriteToUDP(buf, ipv4Addr); err != nil {
last = err

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've changed the error handling behavior of this function without explaining why. We're now falling-thru on error to try another the unicast conn, but still returning the error, which seems like the worst of both worlds.

Address review feedback:
- Do not return a partial write error if any socket succeeds
- Only surface an error when every attempted write fails
- Add unit tests covering multicast+unicast writes and partial failure
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.

mDNS queries sent via unicast connection instead of multicast - causes discovery failures for certain devices

2 participants