Skip to content

Pubsub Subscription reconnects every 3 seconds #2139

@rtunazzz

Description

@rtunazzz

Pubsub subscription disconnects and reconnects every 3 seconds, raising an i/o timeout error.

Expected Behavior

Work as intended, without raising any errors

Current Behavior

Disconnects from Redis & logs discarding bad PubSub connection: read tcp [::1]:50044->[::1]:6379: i/o timeout every 3 seconds.
Here are the logs from my redis server, running default configuration with verbose loglevel:
image

From what I noticed, everything works as expected when I downgrade to v8.

Steps to Reproduce

package main

import (
	"context"
	"log"

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

var ctx = context.Background()

func main() {
	rdb := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	// There is no error because go-redis automatically reconnects on error.
	pubsub := rdb.Subscribe(ctx, "test")
	// Close the subscription when we are done.
	defer pubsub.Close()

	// Wait for confirmation that subscription is created before publishing anything.
	_, err := pubsub.Receive(ctx)
	if err != nil {
		panic(err)
	}

	ch := pubsub.Channel()
	for {
		select {
		case <-ctx.Done():
			return
		case msg := <-ch:
			log.Println(msg)
		}
	}
}

Code above results in:

go run main.go
redis: 2022/07/01 18:03:54 pubsub.go:159: redis: discarding bad PubSub connection: read tcp [::1]:50222->[::1]:6379: i/o timeout
redis: 2022/07/01 18:03:57 pubsub.go:159: redis: discarding bad PubSub connection: read tcp [::1]:50223->[::1]:6379: i/o timeout

Context (Environment)

  • MacOS Monterey 12.4 (I've also tested w docker on golang:1.18-alpine and got the same result)
  • Golang version 1.18
  • github.com/go-redis/redis/v9 v9.0.0-beta.1

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