Skip to content

Commit 69be86f

Browse files
committed
fix ring publishj
1 parent 896f2ce commit 69be86f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

server/lib/events/capturesession.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ func (s *CaptureSession) Start(captureSessionID string) {
3333

3434
// Publish wraps ev in an Envelope, truncates if needed, then writes to
3535
// FileWriter (durable) before RingBuffer (in-memory fan-out).
36-
// The mutex is held only for envelope construction; file I/O and ring publish
37-
// happen outside the lock (both are internally synchronized).
36+
// The mutex is held through ring publish to preserve seq ordering for readers.
37+
// File I/O happens outside the lock since FileWriter has its own mutex and
38+
// JSONL lines are independent (no ordering requirement).
3839
func (s *CaptureSession) Publish(ev Event) {
3940
if ev.Ts == 0 {
4041
ev.Ts = time.Now().UnixMilli()
@@ -50,14 +51,14 @@ func (s *CaptureSession) Publish(ev Event) {
5051
Event: ev,
5152
}
5253
env, data := truncateIfNeeded(env)
54+
s.ring.Publish(env)
5355
s.mu.Unlock()
5456

5557
if data == nil {
5658
slog.Error("capture_session: marshal failed, skipping file write", "seq", env.Seq, "category", env.Event.Category)
5759
} else if err := s.files.Write(env, data); err != nil {
5860
slog.Error("capture_session: file write failed", "seq", env.Seq, "category", env.Event.Category, "err", err)
5961
}
60-
s.ring.Publish(env)
6162
}
6263

6364
// NewReader returns a Reader positioned at the start of the ring buffer.

0 commit comments

Comments
 (0)