1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-12-02 20:22:52 +00:00

prevent stream corruption

This commit is contained in:
Laura
2025-11-07 18:33:49 +01:00
parent 9565b4a92b
commit 6d2e89ca51

View File

@@ -32,6 +32,7 @@ type Chunk struct {
} }
type Stream struct { type Stream struct {
mx sync.Mutex
wr http.ResponseWriter wr http.ResponseWriter
ctx context.Context ctx context.Context
} }
@@ -81,6 +82,9 @@ func GetErrorMessage(err error) string {
} }
func (s *Stream) WriteChunk(chunk *Chunk) error { func (s *Stream) WriteChunk(chunk *Chunk) error {
s.mx.Lock()
defer s.mx.Unlock()
debugIf(chunk.Type == ChunkError, "error: %v", chunk.Data) debugIf(chunk.Type == ChunkError, "error: %v", chunk.Data)
if err := s.ctx.Err(); err != nil { if err := s.ctx.Err(); err != nil {