redis / go-redis

Redis Go client
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
20.21k stars 2.38k forks source link

monitor command breaks due to ReadTimeout #3079

Open stlava opened 3 months ago

stlava commented 3 months ago

Expected Behavior

Monitor command should work.

Current Behavior

If you do not set a large ReadTimeout on the client when using the monitor command then the socket timeout is hit but that error is never propagated back in any way so the channel listener is left in a blocked state.

Possible Solution

Either:

  1. Update docs to inform users that they are responsible for detecting timeouts when listening to the channel
  2. A ReadTimeout (or any other error) should be propagated back to user via closing the monitor channel

Steps to Reproduce

  1. Start client

    client := redis.NewClient(&redis.Options{
        Addr: "127.0.0.1:6379",
        // ReadTimeout: 1 * time.Minute,
    })
    
    stream := make(chan string, 1000)
    monitorCmd := client.Monitor(ctx, stream)
    monitorCmd.Start()
    
    for {
        var msg string
    
        select {
        case <-ctx.Done():
            fmt.Println("ctx done")
        case msg = <-stream:
            fmt.Println("message")
        }
    
        fmt.Println(msg)
    }
  2. Wait a second and then via cli perform any redis operation

  3. Check output from client