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
This commit is contained in:
Keegan Carruthers-Smith 2024-04-10 15:11:43 +02:00 committed by GitHub
parent c40b376032
commit 1d07a278bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}