[GH-ISSUE #556] 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 #265

Open
opened 2026-03-02 05:20:03 +03:00 by kerem · 13 comments
Owner

Originally created by @yun36524 on GitHub (Oct 13, 2022).
Original GitHub issue: https://github.com/hibiken/asynq/issues/556

Originally assigned to: @hibiken on GitHub.

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

Originally created by @yun36524 on GitHub (Oct 13, 2022). Original GitHub issue: https://github.com/hibiken/asynq/issues/556 Originally assigned to: @hibiken on GitHub. 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
Author
Owner

@huizhang001 commented on GitHub (Oct 13, 2022):

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

<!-- gh-comment-id:1277282838 --> @huizhang001 commented on GitHub (Oct 13, 2022): Can you paste the code? Let me have a look? @yun36524
Author
Owner

@huizhang001 commented on GitHub (Oct 13, 2022):

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

<!-- gh-comment-id:1277289664 --> @huizhang001 commented on GitHub (Oct 13, 2022): I think there is a problem with your Redis port port:6379 ?
Author
Owner

@yun36524 commented on GitHub (Oct 13, 2022):

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
}
<!-- gh-comment-id:1277295747 --> @yun36524 commented on GitHub (Oct 13, 2022): > 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. ```golang 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 } ```
Author
Owner

@yun36524 commented on GitHub (Oct 13, 2022):

Anybody here?

<!-- gh-comment-id:1277349423 --> @yun36524 commented on GitHub (Oct 13, 2022): Anybody here?
Author
Owner

@huizhang001 commented on GitHub (Oct 13, 2022):

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

<!-- gh-comment-id:1277393187 --> @huizhang001 commented on GitHub (Oct 13, 2022): I used your code, but it didn't reproduce. The suspicion is still related to Redis....
Author
Owner

@yun36524 commented on GitHub (Oct 13, 2022):

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"))
}
<!-- gh-comment-id:1277540078 --> @yun36524 commented on GitHub (Oct 13, 2022): > 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? ```golang 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")) } ```
Author
Owner

@yun36524 commented on GitHub (Oct 18, 2022):

Can someone help me

<!-- gh-comment-id:1281791880 --> @yun36524 commented on GitHub (Oct 18, 2022): Can someone help me
Author
Owner

@xuyang2 commented on GitHub (Oct 18, 2022):

@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
		},
	)
}
<!-- gh-comment-id:1281862518 --> @xuyang2 commented on GitHub (Oct 18, 2022): @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 }, ) } ```
Author
Owner

@huizhang001 commented on GitHub (Oct 20, 2022):

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

<!-- gh-comment-id:1285337365 --> @huizhang001 commented on GitHub (Oct 20, 2022): If you use a mac, I suggest you re install redis with brew!!!!!
Author
Owner

@Crystalplan commented on GitHub (Nov 7, 2022):

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

<!-- gh-comment-id:1305036373 --> @Crystalplan commented on GitHub (Nov 7, 2022): I have the same problem and hope to get help. Redis is installed with Docker. Redis is normally in use
Author
Owner

@larryclean commented on GitHub (Nov 25, 2022):

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

<!-- gh-comment-id:1327033384 --> @larryclean commented on GitHub (Nov 25, 2022): @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"
Author
Owner

@Crystalplan commented on GitHub (Dec 16, 2022):

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

<!-- gh-comment-id:1354365623 --> @Crystalplan commented on GitHub (Dec 16, 2022): > 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
Author
Owner

@fzpixzj90h7baqieoop5hg commented on GitHub (Oct 31, 2023):

use localhost,,,

<!-- gh-comment-id:1786514604 --> @fzpixzj90h7baqieoop5hg commented on GitHub (Oct 31, 2023): use localhost,,,
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#265
No description provided.