diff --git a/changes/20250729141206.bugfix b/changes/20250729141206.bugfix new file mode 100644 index 0000000000..e5f91a1ae5 --- /dev/null +++ b/changes/20250729141206.bugfix @@ -0,0 +1 @@ +:bug: Fix zerolog closing the writer passed to it diff --git a/utils/logs/writer.go b/utils/logs/writer.go index 6730e6e466..c5f4e64264 100644 --- a/utils/logs/writer.go +++ b/utils/logs/writer.go @@ -41,6 +41,7 @@ func (w *MultipleWritersWithSource) AddWriters(writers ...WriterWithSource) erro } return nil } + func (w *MultipleWritersWithSource) Write(p []byte) (n int, err error) { writers, err := w.GetWriters() if err != nil { @@ -133,12 +134,24 @@ func NewDiodeWriterForSlowWriterWithoutClosing(slowWriter WriterWithSource, ring return newDiodeWriterForSlowWriter(false, slowWriter, ringBufferSize, pollInterval, droppedMessagesLogger) } +type nonCloseableWriter struct { + io.Writer +} + +func (ncw nonCloseableWriter) Close() error { + return nil +} + func newDiodeWriterForSlowWriter(closeWriterOnClose bool, slowWriter WriterWithSource, ringBufferSize int, pollInterval time.Duration, droppedMessagesLogger Loggers) WriterWithSource { closerStore := parallelisation.NewCloserStore(false) if closeWriterOnClose { closerStore.RegisterCloser(slowWriter) } - d := diode.NewWriter(slowWriter, ringBufferSize, pollInterval, func(missed int) { + + // We pass a wrapper that "overrides" the close method to do nothing, + // this is because we control the writer's close behaviour through the `closeWriterOnClose` check + ncw := nonCloseableWriter{slowWriter} + d := diode.NewWriter(ncw, ringBufferSize, pollInterval, func(missed int) { if droppedMessagesLogger != nil { droppedMessagesLogger.LogError(fmt.Sprintf("Logger dropped %d messages", missed)) }