hibiken / asynq

Simple, reliable, and efficient distributed task queue in Go
MIT License
9.92k stars 710 forks source link

redis: discarding bad PubSub connection: read tcp 127.0.0.1:52914->127.0.0.1:63791: i/o timeout[BUG] Description of the bug #556

Open yun36524 opened 2 years ago

yun36524 commented 2 years ago

redis: discarding bad PubSub connection: read tcp 127.0.0.1:52914->127.0.0.1:63791: i/o timeout I can't run it, my redis is working fine

huizhang001 commented 2 years ago

Can you paste the code? Let me have a look? @yun36524

huizhang001 commented 2 years ago

I think there is a problem with your Redis port port:6379 ?

yun36524 commented 2 years ago

I think there is a problem with your Redis port port:6379 ?

I'm sure there's nothing wrong with redis because my application is using it properly. I am copying the official code and it does not work.

func InitServer() {
    srv := asynq.NewServer(
        asynq.RedisClientOpt{Addr: "127.0.0.1:63791", Password: "***", ReadTimeout: 10 * time.Second, WriteTimeout: 0},
        asynq.Config{
            // Specify how many concurrent workers to use
            Concurrency: 10,
            // Optionally specify multiple queues with different priority.
            Queues: map[string]int{
                "critical": 6,
                "default":  3,
                "low":      1,
            },
            // See the godoc for other configuration options
        },
    )

    // mux maps a type to a handler
    mux := asynq.NewServeMux()
    mux.HandleFunc("msg", HandleEmailDeliveryTask)
    // ...register other handlers...

    if err := srv.Run(mux); err != nil {
        log.Fatalf("could not run server: %v", err)
    }
}
func HandleEmailDeliveryTask(ctx context.Context, t *asynq.Task) error {

    fmt.Println("----------------")
    // Email delivery code ...
    return nil
}
yun36524 commented 2 years ago

Anybody here?

huizhang001 commented 2 years ago

I used your code, but it didn't reproduce. The suspicion is still related to Redis....

yun36524 commented 2 years ago

I used your code, but it didn't reproduce. The suspicion is still related to Redis....

I can run this code normally. Is there any configuration to pay attention to in redis?

import(
    "github.com/go-redis/redis/v8"
    "fmt"
)
func main(){
    client := redis.NewClient(&redis.Options{
        Addr:     "127.0.0.1:63791",
        Password: "***",
    })
    client.SetNX(context.Background(), "msg", "hello", 10*time.Second)
    fmt.Println(client.Get(context.Background(), "msg"))
}
yun36524 commented 2 years ago

Can someone help me

xuyang2 commented 2 years ago

@yun36524 This is how I manage redis client, don't know if this will work for you:

import (
    "github.com/go-redis/redis/v8"
    "github.com/hibiken/asynq"
)

type CloseNopClient struct {
    redis.UniversalClient
}

// Close do nothing
// asynq.Scheduler Shutdown() will call client.Close()
func (c *CloseNopClient) Close() error {
    return nil
}

type clientHolder struct {
    client redis.UniversalClient
}

var _ asynq.RedisConnOpt = (*clientHolder)(nil)

func (opt clientHolder) MakeRedisClient() interface{} {
    return opt.client
}

func NewRedisConnOpt(client redis.UniversalClient) asynq.RedisConnOpt {
    return &clientHolder{
        client: &CloseNopClient{
            UniversalClient: client,
        },
    }
}

func Example() {
    client := redis.NewClient(&redis.Options{
        Addr:     "127.0.0.1:63791",
        Password: "***",
    })

    srv := asynq.NewServer(
        NewRedisConnOpt(client),
        asynq.Config{
            // Specify how many concurrent workers to use
            Concurrency: 10,
            // Optionally specify multiple queues with different priority.
            Queues: map[string]int{
                "critical": 6,
                "default":  3,
                "low":      1,
            },
            // See the godoc for other configuration options
        },
    )
}
huizhang001 commented 2 years ago

If you use a mac, I suggest you re install redis with brew!!!!!

Crystalplan commented 2 years ago

I have the same problem and hope to get help. Redis is installed with Docker. Redis is normally in use

larryclean commented 1 year ago

@hibiken Hi,about the problem.I found that it is related to the redis option. when db>0 log print "discarding bad PubSub connection" db=0 ,password="" don't print. db=0 password="xxxx" log print "discarding bad PubSub connection"

Crystalplan commented 1 year ago

Can someone help me

My solution is: asynq.NewServer( asynq.RedisClientOpt{Addr: "127.0.0.1:63791", Password: "***", ReadTimeout: -1, WriteTimeout: 0}............................

ReadTimeout set -1,won't print anymore

fzpixzj90h7baqieoop5hg commented 1 year ago

use localhost,,,