Skip to content

FE-29496 - Protocol correctness fixes - #6

Open
craftyjon wants to merge 16 commits into
masterfrom
craftyjon/FE-29496/protocol-correctness
Open

craftyjon wants to merge 16 commits into
masterfrom
craftyjon/FE-29496/protocol-correctness

Conversation

@craftyjon

@craftyjon craftyjon commented Nov 13, 2026 •

Copy link
Copy Markdown

Fixes a number of protocol correctness issues with the library that were identified by AI analysis after investigating mDNS flooding behavior on the office network.

Note: there are a number of correctness issues with the client (resolver) side of this library that are left alone because Formlabs code doesn't make use of it (we only use the responder)

Also makes the library testable and adds tests.

The most impactful change is 184ab3c which gets rid of an infinite network traffic generator.
But because of fixing this, it's important that we handle some other edge cases of the protocol better, so that the mDNS responses we do send out are more likely to work:

  1. queries with known answers were being totally dropped instead of handled properly
  2. cases of names were not being correctly normalized, so known-answer handling never would have worked anyway
  3. truncated queries were being dropped instead of handled, meaning on networks with more than a certain number of printers (Claude estimates about 28) queries would never be answered
  4. Replies were telling clients to flush their cache of other printers, which is probably contributing to why PreForm was maintaining its own cache?
  5. Printers weren't handling replies on multiple interfaces when they were connected to both Ethernet and Wi-Fi
  6. Dual-stack queries were going out duplicated, causing 2x more network traffic than required

See also: https://datatracker.ietf.org/doc/html/rfc6762

Further AI analysis found many other places where this library does not implement the standard or doesn't fully meet it, but I'm trying to focus on just the ones that are either proven to cause a problem with our usage or are analytically likely to be relevant to us.

Test plan:

On an isolated network:

  • Log traffic from printer over Ethernet
  • With a Windows PreForm
  • With a macOS PreForm
  • When changing to Wi-Fi

On the HQ network, repeat similar.

Rollout plan:

Since this change is potentially risky, I would like to roll it out gradually using feature flags, in order to be able to start with testing on Formlabs networks and then maybe customer networks. To do this:

  1. I've changed the module name to bonjour/v2
  2. a mordor PR enables feature flag support in bonsoir and can switch what version of this library it pulls in based on a feature flag

Since mordor pins the commit in this repo, merging this is a no-op for existing mordor.

This comment was marked as outdated.

This comment was marked as outdated.

@craftyjon
craftyjon force-pushed the craftyjon/FE-29496/protocol-correctness branch from a08c23d to eb7e841 Compare November 16, 2026 19:07
@craftyjon
craftyjon requested a balanced review from Copilot November 16, 2026 19:08

This comment was marked as outdated.

@craftyjon
craftyjon force-pushed the craftyjon/FE-29496/protocol-correctness branch from eb7e841 to 51c2eeb Compare November 16, 2026 19:32
@craftyjon
craftyjon requested a balanced review from Copilot November 16, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues remain in DNS name canonicalization, known-answer accumulation across continuations, legacy multi-question responses, and half-TTL suppression thresholds.

4 open issues
4 resolved since last review

Review effort: Balanced

Comment thread client.go Resolved
Comment thread server.go Resolved
Comment thread server.go Resolved
Comment thread server.go Resolved
@craftyjon
craftyjon force-pushed the craftyjon/FE-29496/protocol-correctness branch from 51c2eeb to dd28166 Compare November 16, 2026 20:23
Do not use SetReply, which copies the query info
into the response in a way that violates the standard.
This should improve discovery of printers on networks with
lots of the same type of printer, since once you have more
than can fit into a single packet, queries would have been
dropped instead of answered.
@craftyjon
craftyjon force-pushed the craftyjon/FE-29496/protocol-correctness branch from dd28166 to 184ab3c Compare November 16, 2026 20:30
@craftyjon
craftyjon requested a balanced review from Copilot November 16, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved protocol issues break legacy-query reply matching, incorrectly suppress answers for odd TTLs, and trigger premature responses to truncated queries.

6 open issues

Review effort: Balanced

Comment thread server.go Outdated
Comment on lines +400 to +403
// ErrTruncated only reports the TC bit; the message is fully unpacked. A truncated
// query is answered like any other. Its known answers go on in further packets,
// which are not waited for: at worst we repeat an answer the querier listed there.
if err := request.query.Unpack(packet); err != nil && err != dns.ErrTruncated {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Intentional. the previous code drops truncated queries outright; this answers them using the known answers in the first packet. Keeping track of continuations introduces a lot more complexity and edge-case handling. I started down the path of implementing this but rolled it back and would prefer to prove we need it before revisiting.

Comment thread server.go
Comment on lines 428 to +430
resp = dns.Msg{}
resp.SetReply(&request.query)
resp.Response = true
resp.Authoritative = true

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

PreForm does not use a legacy query path. Not a factor.

@craftyjon
craftyjon requested a review from mttong November 18, 2026 14:24
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.

2 participants