Merge pull request #458 from Coff0xc/fix/logsink-closed-subscriber

fix(server): do not send a log line to a closed subscriber
This commit is contained in:
BaaRai
2026-11-22 07:55:33 +01:00
committed by GitHub
3 changed files with 32 additions and 9 deletions
+1
View File
@@ -6,6 +6,7 @@ All notable changes to this project are documented in this file. The format is b
### Fixed
- **Live log subscribers can no longer crash the process**: a client disconnect closes its log channel. The sink now delivers a line while it still holds the subscriber lock, so that close cannot land in the middle of the send.
- **Docker Compose database passwords with URL-special characters**: `docker-compose.yml` no longer pastes `POSTGRES_PASSWORD` into `ARTEX_PG_DSN`. The server builds the URL from `ARTEX_PG_HOST`, `ARTEX_PG_PORT`, `ARTEX_PG_USER`, `ARTEX_PG_PASSWORD`, `ARTEX_PG_DBNAME` and `ARTEX_PG_SSLMODE`, percent-encoding the user and password, so `/`, `?`, `%`, `@`, `:` and spaces connect. An explicit `ARTEX_PG_DSN` still wins and is not rewritten. `ARTEX_PG_PASSWORD` is removed from the environment with the other startup secrets (#450).
## [0.7.0] - 2026-11-21
+8 -9
View File
@@ -152,9 +152,15 @@ func (s *logSinkT) add(l LogLine) {
s.ring = s.ring[len(s.ring)-s.cap:]
}
ch := s.dbCh
subs := make([]chan LogLine, 0, len(s.subs))
// Fan-out stays under the lock. subscribe's cancel removes the channel and
// then closes it; a send on a closed channel panics even inside select, so
// the send and the close must not interleave. The send does not block: a
// full buffer drops the line.
for sub := range s.subs {
subs = append(subs, sub)
select {
case sub <- l:
default:
}
}
s.mu.Unlock()
@@ -165,13 +171,6 @@ func (s *logSinkT) add(l LogLine) {
default:
}
}
for _, sub := range subs {
select {
case sub <- l:
default:
}
}
}
// recent returns ring lines with Seq > since (capped to limit), and the latest seq.
+23
View File
@@ -0,0 +1,23 @@
package server
import (
"io"
"sync"
"testing"
)
func TestLogSinkUnsubscribeDuringAddDoesNotPanic(t *testing.T) {
s := &logSinkT{cap: 8, subs: map[chan LogLine]struct{}{}, out: io.Discard}
var wg sync.WaitGroup
for i := 0; i < 32; i++ {
_, unsub := s.subscribe()
wg.Add(1)
go func() {
defer wg.Done()
unsub()
}()
s.add(LogLine{Text: "line"})
}
wg.Wait()
s.add(LogLine{Text: "after"})
}