ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)
Go aiai-agentsautonomous-agentsbug-bountydockergolanglinuxllmmcpnextjspenetration-testingpentestpostgresqlreareactred-teamsecuritysecurity-automationsqlitetypescript
fix(server): do not send a log line to a closed subscriber
Coff0xc9a8f3665740e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5af6fb6..6fb80ba 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -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-21diff --git a/server/logsink.go b/server/logsink.goindex cff3c68..36fac4b 100644--- a/server/logsink.go+++ b/server/logsink.go@@ -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.diff --git a/server/logsink_test.go b/server/logsink_test.gonew file mode 100644index 0000000..182098b--- /dev/null+++ b/server/logsink_test.go@@ -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"})+}