Fix /pairings handler rejecting ListPairings with "tlv8: EOF"#67
Open
hughobrien wants to merge 1 commit into
Open
Fix /pairings handler rejecting ListPairings with "tlv8: EOF"#67hughobrien wants to merge 1 commit into
hughobrien wants to merge 1 commit into
Conversation
hughobrien
added a commit
to hughobrien/keylight-hap
that referenced
this pull request
Jun 19, 2026
The bundled hap (v0.0.35) silently drops pipelined requests on encrypted connections: conn.Read recreates and discards bufio's read-ahead each Decrypt, losing the 2nd+ back-to-back request. During pairing this drops the admin's AddPairing calls for home hubs (HomePods/Apple TV), so those controllers get an empty body (pairings.go: tlv8: EOF) and never register — they loop forever on "not paired with <id> yet". Replace with hughobrien/hap@bd1f7e7, which persists the bufio.Reader across Read/Decrypt. Submitted upstream as brutella/hap#67. Drop this replace once that merges and is tagged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
The /pairings handler decoded the request into a struct that marked
Identifier (tag 1) as required. A ListPairings request carries only
Method (tag 0) and State (tag 6) — no Identifier — so the tag-keyed
reader returned io.EOF for the missing required field and the handler
rejected the request (HTTP 400, "tlv8: EOF").
iOS uses ListPairings to reconcile a home's controllers (resident
HomePods/Apple TVs, additional devices). Because the request always
failed, iOS could never converge: it retried endlessly, re-attempting
RemovePairing for controllers it wanted to drop and leaving others
looping on pair-verify ("not paired with <id> yet").
Mark Identifier optional, completing the partial fix in 340cbe4 (brutella#21)
which made PublicKey and Permission optional but left Identifier
required. Resolves the unmarshal failure reported in brutella#21 and brutella#44.
Added a handler-level regression test using request bodies captured
from a real iOS controller.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bd1f7e7 to
78932fb
Compare
This was referenced Jun 19, 2026
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
The
/pairingshandler decodes requests into a struct that marksIdentifier(tag 1) as required. A ListPairings request contains onlyMethod(tag 0) andState(tag 6); it has noIdentifier. The tag-keyed reader returnsio.EOFfor the missing required field, sotlv8.UnmarshalReaderfails and the handler responds HTTP 400, loggingtlv8: EOF.iOS issues ListPairings to enumerate an accessory's paired controllers. With the request always failing, the controller set never reconciles; ListPairings, RemovePairing, and pair-verify are retried indefinitely.
Change
Mark
Identifieroptional. 340cbe4 (#21) previously madePublicKeyandPermissionoptional but leftIdentifierrequired, so ListPairings still failed. Fixes #21 and #44.Captured requests
pairings()was instrumented to logContentLength, the read body length and error, and the raw bytes immediately beforetlv8.UnmarshalReader. Observed during pairing with a real controller:The failing body is fully read (
bodyLen=6,readErr=<nil>); it is not empty or truncated. Decoding000105060101:Test
TestPairingsHandlerRequestsreplays the captured bodies against the handler.master:
this PR: