Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Commit caf79f2

Browse files
authored
Merge pull request #94 from sei-protocol/yzang/SEI-9878
Fix nil pointer issue for corrupted log recovery
2 parents 5252073 + 1cade31 commit caf79f2

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

stream/changelog/changelog.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ func (stream *Stream) Close() error {
231231

232232
// open opens the replay log, try to truncate the corrupted tail if there's any
233233
func open(dir string, opts *wal.Options) (*wal.Log, error) {
234+
if opts == nil {
235+
opts = wal.DefaultOptions
236+
}
234237
rlog, err := wal.Open(dir, opts)
235238
if errors.Is(err, wal.ErrCorrupt) {
236239
// try to truncate corrupted tail

stream/changelog/changelog_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,25 @@ func TestAsyncWrite(t *testing.T) {
158158
require.NoError(t, err)
159159
require.Equal(t, uint64(3), lastIndex)
160160
}
161+
162+
func TestOpenWithNilOptions(t *testing.T) {
163+
dir := t.TempDir()
164+
165+
// Test that open function handles nil options correctly
166+
log, err := open(dir, nil)
167+
require.NoError(t, err)
168+
require.NotNil(t, log)
169+
170+
// Verify the log is functional by checking first and last index
171+
firstIndex, err := log.FirstIndex()
172+
require.NoError(t, err)
173+
require.Equal(t, uint64(0), firstIndex)
174+
175+
lastIndex, err := log.LastIndex()
176+
require.NoError(t, err)
177+
require.Equal(t, uint64(0), lastIndex)
178+
179+
// Clean up
180+
err = log.Close()
181+
require.NoError(t, err)
182+
}

stream/changelog/utils.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ func LogPath(dir string) string {
1818

1919
// GetLastIndex returns the last written index of the replay log
2020
func GetLastIndex(dir string) (index uint64, err error) {
21-
rlog, err := open(dir, nil)
21+
rlog, err := open(dir, &wal.Options{
22+
NoSync: true,
23+
NoCopy: true,
24+
})
2225
if err != nil {
2326
return 0, err
2427
}

0 commit comments

Comments
 (0)