From 6d2e89ca51c395124a7b759b5da2c3d8fa7b1a3b Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 7 Nov 2025 18:33:49 +0100 Subject: [PATCH] prevent stream corruption --- stream.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stream.go b/stream.go index 674f32d..fb7fec6 100644 --- a/stream.go +++ b/stream.go @@ -32,6 +32,7 @@ type Chunk struct { } type Stream struct { + mx sync.Mutex wr http.ResponseWriter ctx context.Context } @@ -81,6 +82,9 @@ func GetErrorMessage(err error) string { } func (s *Stream) WriteChunk(chunk *Chunk) error { + s.mx.Lock() + defer s.mx.Unlock() + debugIf(chunk.Type == ChunkError, "error: %v", chunk.Data) if err := s.ctx.Err(); err != nil {