Repository navigation
Fix HomeKit server closing the controller connection when a stream ends - #2776
Closed
RyoKusnadi wants to merge 1 commit into
Closed
RyoKusnadi wants to merge 1 commit into
RyoKusnadi wants to merge 1 commit into
Conversation
Consumer.Stop called core.Connection.Stop, which closes the Transport. For the HomeKit consumer that is the controller's HAP session, so ending a video session dropped the whole connection and the response to the end request failed with "use of closed network connection". Fixes AlexxIT#2772 Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
Owner
|
Thanks! Your AI isn't smart enough. This is wrong fix. You shouldn't remove default |
Contributor
Author
|
Ah, got it. I missed that the default |
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.
Problem: Every time you close a camera view in the Home app, go2rtc logs
write tcp ...: use of closed network connectionfrominternal/homekit/server.go:125. The error isn't just noise: go2rtc has closed the iPhone's HAP connection, so the iPhone has to connect and pair-verify again for its next request.How it happens: Closing the view sends
PUT /characteristicswith aSelectedStreamConfigurationwhose command is End.server.SetCharacteristicfinds the consumer and callsconsumer.Stop().homekit.Consumer.Stopcallscore.Connection.Stop(), which closesTransport, and for this consumerTransportis the controller's HAP conn (NewConsumer(conn, ...)).handleRequestthen writes the 204 for that same PUT to the closed conn, and the handler returns the error. The same close happens when the consumer's deadline fires, throughstream.RemoveConsumer.Steps to reproduce: expose a stream as a HomeKit camera, open it in the Home app, close it.
Expected: no error, and the HAP connection stays open.
Actual: the error above, and the HAP connection is closed.
Fix:
Consumer.Stopcloses its senders and stops the deadline, but no longer closes the conn. The HAP session belongs to the controller and outlives one video session. It's still closed when the controller goes away (defer conn.Close()ininternal/homekit/server.go).Scope:
homekit.Client.Stop) is left as is: there go2rtc is the controller, so closing its own HAP connection is right.srtp.DelSessionfor its sessions, while the producer does. I left that out: removing the last session closes the shared UDP listener, so it's a separate change.Consumer.Stop(talkback) but keepsc.Connection.Stop(), so one of the two will need a small rebase.Testing: new
TestConsumerStopKeepsControllerConn(pkg/homekit) stops a consumer on anet.Pipeand writes to the conn. Before the fix:Received unexpected error: io: read/write on closed pipe. After: it passes.go test ./pkg/homekit/ ./pkg/hap/... ./internal/homekit/passes,go vetandgofmt -lare clean.Environment: master @ 9e1d6ab, go1.27.4, darwin/arm64.
Fixes #2772