Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubSubConn.ReceiveWithTimeout allways has Error #676

Open
brucelin-cn opened this issue Oct 16, 2024 · 0 comments
Open

PubSubConn.ReceiveWithTimeout allways has Error #676

brucelin-cn opened this issue Oct 16, 2024 · 0 comments

Comments

@brucelin-cn
Copy link

brucelin-cn commented Oct 16, 2024

func runRecv(mq *MessageQueue) {
	conn := mq.pool.Get()
	defer conn.Close()
	tmp := rand.Intn(1000000000)
	var runningErr error
	psc := redis.PubSubConn{Conn: conn}
	for {

		v := psc.ReceiveWithTimeout(100 * time.Millisecond)
		switch msg := v.(type) {
		case redis.Message:
			log.Info("Message", tmp, msg.Channel, msg.Data)
			mq.broadcastMessage(msg.Channel, msg.Data)
		case redis.Subscription:
			
			log.Info("Subscription change:%v %s: %s %d\n", tmp, msg.Kind, msg.Channel, msg.Count)
		case error:

			if msg != nil {
				if nErr, ok := msg.(net.Error); ok && nErr.Timeout() {			

					log.Error("Redis Timeout error:", tmp, msg, conn.Err())
					if err := psc.Subscribe("foo"); err != nil {
						log.Info("Ping failed:", err)
						runningErr = err
					}
					continue
				} else {
					
					runningErr = msg
					log.Error("Redis error:", tmp, msg, conn.Err(), runningErr)

				}
			}

		}

	}
}

During the second loop, the error "use of closed network connection" keeps occurring. at line:log.Error("Redis error:", xxxx)

maybe there is some bugs here?

func (c *conn) ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error) {
      //  should be check is Timeout Err?
	if reply, err = c.readReply(); err != nil {
		return nil, c.fatal(err)
	}
     //

}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant