From 1d07a278bb30de848db1b27e65c2a306a5bff8ee Mon Sep 17 00:00:00 2001 From: Keegan Carruthers-Smith Date: Wed, 10 Apr 2024 15:11:43 +0200 Subject: [PATCH] streaming: only call flush if writes succeeded (#61752) This is a speculative change to reduce the chances of misuse of the streaming http event writer (SSE). We are seeing panics in attribution search since it is trying to write events once the request has finished. From the stack traces it seems the http package safely handles calls to Write without panicing but does not do the same for Flush. This change also seems more correct. Note: this does not address the root cause of the panics, but should make it far less likely to occur. Test Plan: go test --- internal/search/streaming/http/writer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/search/streaming/http/writer.go b/internal/search/streaming/http/writer.go index 606b397f610..f6f992a8e3f 100644 --- a/internal/search/streaming/http/writer.go +++ b/internal/search/streaming/http/writer.go @@ -106,7 +106,10 @@ func (e *Writer) EventBytes(event string, dataLine []byte) (err error) { write(dataLine) write([]byte("\n\n")) - e.flush() + // only need to call flush if writes succeeded. + if err == nil { + e.flush() + } return err }