asynq icon indicating copy to clipboard operation
asynq copied to clipboard

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

Open yun36524 opened this issue 1 year ago • 13 comments

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

yun36524 avatar Oct 13 '22 08:10 yun36524

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

huizhang001 avatar Oct 13 '22 09:10 huizhang001

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

huizhang001 avatar Oct 13 '22 09:10 huizhang001

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 avatar Oct 13 '22 09:10 yun36524

Anybody here?

yun36524 avatar Oct 13 '22 09:10 yun36524

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

huizhang001 avatar Oct 13 '22 10:10 huizhang001

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 avatar Oct 13 '22 12:10 yun36524

Can someone help me

yun36524 avatar Oct 18 '22 04:10 yun36524

@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
		},
	)
}

xuyang2 avatar Oct 18 '22 06:10 xuyang2

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

huizhang001 avatar Oct 20 '22 11:10 huizhang001

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

Crystalplan avatar Nov 07 '22 03:11 Crystalplan

@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"

larryclean avatar Nov 25 '22 05:11 larryclean

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

Crystalplan avatar Dec 16 '22 08:12 Crystalplan

use localhost,,,

fzpixzj90h7baqieoop5hg avatar Oct 31 '23 06:10 fzpixzj90h7baqieoop5hg