gomodule / gomodule/redigo

PubSubConn.ReceiveWithTimeout allways has Error

Open
#676 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
9.9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

```
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)
}
//

}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.