Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special lastId=$ not working with XREAD #322

Closed
gpt900 opened this issue Apr 12, 2023 · 2 comments · Fixed by #324
Closed

Special lastId=$ not working with XREAD #322

gpt900 opened this issue Apr 12, 2023 · 2 comments · Fixed by #324

Comments

@gpt900
Copy link

gpt900 commented Apr 12, 2023

How to reproduce:

package main

import (
	"context"
	"testing"
	"time"

	"github.com/alicebob/miniredis/v2"
	"github.com/go-redis/redis/v8"
)

func TestXreadFromFirst(t *testing.T) {
	s := miniredis.RunT(t)
	defer s.Close()

	client := redis.NewClusterClient(&redis.ClusterOptions{
		Addrs:     []string{s.Addr()},
	})

	client.XRead(context.Background(), &redis.XReadArgs{
		Streams: []string{"testStream", "0"},
		Count:   1,
		Block:   100*time.Millisecond,
	})
}

func TestXreadFromLast(t *testing.T) {
	s := miniredis.RunT(t)
	defer s.Close()

	client := redis.NewClusterClient(&redis.ClusterOptions{
		Addrs:     []string{s.Addr()},
	})

	client.XRead(context.Background(), &redis.XReadArgs{
		Streams: []string{"testStream", "$"},
		Count:   1,
		Block:   100*time.Millisecond,
	})
}

First case works as expected, but second fails with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0xdabe19]

goroutine 22 [running]:
github.com/alicebob/miniredis/v2.(*streamKey).lastID(0xc0000d0080?)
	<local-path>/github.com/alicebob/miniredis/v2@v2.30.0/stream.go:79 +0x39
github.com/alicebob/miniredis/v2.(*Miniredis).cmdXread(0xc0000d0080, 0xc0002e6140, {0xc0001344b7, 0x5}, {0xc00011c490, 0x7, 0x7})
	<local-path>/github.com/alicebob/miniredis/v2@v2.30.0/cmd_stream.go:935 +0x76f
github.com/alicebob/miniredis/v2/server.(*Server).Dispatch(0xc0003db400, 0x0?, {0xc00011c480, 0x8, 0x8})
	<local-path>/github.com/alicebob/miniredis/v2@v2.30.0/server/server.go:217 +0x2ee
github.com/alicebob/miniredis/v2/server.(*Server).servePeer(0x0?, {0x11a5268?, 0xc00048e008})
	<local-path>/github.com/alicebob/miniredis/v2@v2.30.0/server/server.go:185 +0x3d1
github.com/alicebob/miniredis/v2/server.(*Server).ServeConn.func1()
	<local-path>/github.com/alicebob/miniredis/v2@v2.30.0/server/server.go:112 +0xb6
created by github.com/alicebob/miniredis/v2/server.(*Server).ServeConn
	<local-path>/github.com/alicebob/miniredis/v2@v2.30.0/server/server.go:108 +0x12a
@alicebob
Copy link
Owner

alicebob commented Apr 12, 2023 via email

@alicebob
Copy link
Owner

Thanks, should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants