-
Notifications
You must be signed in to change notification settings - Fork 696
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
KeyValue.Watch()
blocks forever for certain values of the keys
parameter
#1608
Comments
Update: I also investigated switching to the new package main
import (
"context"
"log"
"time"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
)
func main() {
conn, err := nats.Connect("localhost:4222")
if err != nil {
log.Fatal(err)
}
js, err := jetstream.New(conn)
if err != nil {
log.Fatal(err)
}
kv, err := js.KeyValue(context.Background(), "foobar")
if err != nil {
log.Fatal(err)
}
// watcher, err := kv.Watch(ctx, "001.>")
watcher, err := kv.Watch(context.Background(), "\"001.>\"")
if err != nil {
log.Fatal(err)
}
defer func() {
if err := watcher.Stop(); err != nil {
log.Fatal(err)
}
}()
var keys []any
ctx, done := context.WithTimeout(context.Background(), 3*time.Second)
defer done()
loop:
for {
select {
case entry := <-watcher.Updates():
if entry == nil {
break loop
}
keys = append(keys, entry.Key())
case <-ctx.Done():
log.Fatal("timeout")
}
}
log.Printf("%v", keys)
} I can, however, now pass a context to Also, the |
Thanks for the detailed report! We will take a look soon. |
@mihaitodor there were 2 issues:
Both will now return an error since both are essentially invalid arguments: |
That's awesome, thank you very much for the quick fixes! |
Partially addresses what is reported in nats-io/nats.go#1608
Both PRs are merged and will be included in the next releases of nats-server and nats.go. |
Observed behavior
The
kv.Watch("\"001.>\"")
call blocks forever if there's a key starting with001.
in Nats KV.Additionally, if you also try
kv.Watch("")
, you get a rather cryptic error:nats: jetstream not enabled
.Expected behavior
kv.Watch()
should reject invalid keys or, at the very least, it shouldn't block forever.Also,
kv.Watch("")
should return a more informative error message, maybe saying that thekeys
parameter cannot be set to an empty string.Server and client version
nats:2.10.12
Docker imagegithub.com/nats-io/nats.go
v1.34.1
client librariesv0.1.4
v1.22.1
(darwin/arm64
)Host environment
OSX Sonoma 14.4.1 on Macbook Pro M3 Max
Steps to reproduce
Run the following shell commands:
Create a
go.mod
file with the following contents:And then write the following code in a file called
main.go
:If you execute
go mod tidy && go run main.go
, you'll see a message containingtimeout
. If you uncomment line 27 and comment out line 28, you should see[001.123]
instead.Additionally, if you try
kv.Watch("")
, you'll get a rather cryptic error:nats: jetstream not enabled
.(cc @codegangsta)
The text was updated successfully, but these errors were encountered: