Skip to content

Commit 07945ac

Browse files
authored
fix: Use clear for mixed batch writer (#1645)
Fixes the issue with `cap` used on `nil` slice introduced in #1553
1 parent ca216b6 commit 07945ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: writers/mixedbatchwriter/mixedbatchwriter.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ func (m *batchManager[A, T]) flush(ctx context.Context) error {
192192
if err != nil {
193193
return err
194194
}
195-
m.batch = nil
195+
clear(m.batch) // GC can work
196+
m.batch = m.batch[:0]
196197
return nil
197198
}
198199

@@ -229,7 +230,8 @@ func (m *insertBatchManager) flush(ctx context.Context) error {
229230
}
230231
m.logger.Debug().Int("len", batchSize).Dur("duration", time.Since(start)).Msg("batch written successfully")
231232

232-
m.batch = nil
233+
clear(m.batch) // GC can work
234+
m.batch = m.batch[:0]
233235
m.curBatchSizeBytes = 0
234236
return nil
235237
}

0 commit comments

Comments
 (0)