Skip to content

PubSubConn.ReceiveWithTimeout allways has Error #676

@brucelin-cn

Description

@brucelin-cn
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)
	}
     //

}


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