Skip to content

pubsub.Receive() will timeout #2175

Closed
@j178

Description

@j178

#2060 cause SetReadDeadline not called, so PubSub.ReceiveTimeout(ctx, 0) will not get a read deadline set, thus it will receive the i/o timeout error after some time. Related #2139.

Expected Behavior

PubSub.ReceiveTimeout(ctx, 0) will block forever until a message is received, So does PubSub.Receive(), PubSub.ReceiveMessage() and PubSub.Channel().

Current Behavior

PubSub.Receive() will timeout if read nothing for sometime.

received subscribe: hello <nil>
redis: 2022/08/03 22:36:54 pubsub.go:168: redis: discarding bad PubSub connection: read tcp [::1]:53016->[::1]:6379: i/o timeout
received <nil> read tcp [::1]:53016->[::1]:6379: i/o timeout
received subscribe: hello <nil>
redis: 2022/08/03 22:36:57 pubsub.go:168: redis: discarding bad PubSub connection: read tcp [::1]:53035->[::1]:6379: i/o timeout
received <nil> read tcp [::1]:53035->[::1]:6379: i/o timeout
received subscribe: hello <nil>

Possible Solution

Revert #2060

Steps to Reproduce

package main

import (
    "context"
    "fmt"

    "github.com/go-redis/redis/v9"
)

func main() {
    c := redis.NewClient(&redis.Options{})
    pubsub := c.Subscribe(context.Background(), "hello")
    for {
        m, err := pubsub.Receive(context.Background())
        fmt.Println("received", m, err)
    }
}

Context (Environment)

Redis: 7.0.3
go-redis: master

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions