Make session key authorization atomic, unblock the encoder on teardown, drop agent privileges unconditionally

This commit is contained in:
Viktor Liu
2026-08-29 09:12:33 +02:00
parent 8b719f0b4e
commit 42450dbfbe
7 changed files with 119 additions and 14 deletions
+7
View File
@@ -198,6 +198,13 @@ func (s *session) serve() {
encoderDone := make(chan struct{})
go s.encoderLoop(encoderDone)
defer func() {
// Close the connection before waiting for the encoder. It may be parked
// in a write to a client that stopped reading, and the only thing that
// would unblock it otherwise is whatever deadline messageLoop last set
// on the shared conn: that leaves the session, and the connection slot
// it holds, alive for as long as that takes. The caller closes the
// connection too; a second Close is harmless.
s.conn.Close()
close(s.encodeCh)
<-encoderDone
}()