Improve logging consistency across the application, handle context cancellation during WebSocket writes, and introduce async ACL reconfiguration for admin events.

This commit is contained in:
2025-09-11 11:37:25 +01:00
parent bb8998fef6
commit bf7ca1da43
13 changed files with 176 additions and 111 deletions

View File

@@ -3,12 +3,15 @@ package app
import (
"context"
"net/http"
"time"
"github.com/coder/websocket"
"lol.mleku.dev/chk"
"utils.orly/atomic"
)
const WriteTimeout = 10 * time.Second
type Listener struct {
*Server
conn *websocket.Conn
@@ -20,7 +23,12 @@ type Listener struct {
}
func (l *Listener) Write(p []byte) (n int, err error) {
if err = l.conn.Write(l.ctx, websocket.MessageText, p); chk.E(err) {
// Use a separate context with timeout for writes to prevent race conditions
// where the main connection context gets cancelled while writing events
writeCtx, cancel := context.WithTimeout(context.Background(), WriteTimeout)
defer cancel()
if err = l.conn.Write(writeCtx, websocket.MessageText, p); chk.E(err) {
return
}
n = len(p)