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

redigo always random errors when many connections coming #55

Closed
Icedroid opened this issue Mar 13, 2014 · 8 comments
Closed

redigo always random errors when many connections coming #55

Icedroid opened this issue Mar 13, 2014 · 8 comments

Comments

@Icedroid
Copy link

I init redis pool in a model package, and one model(one Mysql table one model ) use RedisPool.Get() get a redis conn to DO redis command.

RedisPool = &redis.Pool{
        MaxIdle:     3,
        IdleTimeout: 240 * time.Second,
        TestOnBorrow: func(c redis.Conn, t time.Time) error {
            _, err := c.Do("PING")
            if err != nil {
                logs.Logger.Errorf("redis TestOnBorrow %v", err)
            }
            return err
        },
        Dial: func() (redis.Conn, error) {
            c, err := redis.Dial("tcp", server)
            if err != nil {
                logs.Logger.Errorf("Dail master redis server %s %v", server, err)
                return nil, err
            }
            //if password != "" {
            //  if _, err := c.Do("AUTH", password); err != nil {
            //      c.Close()
            //      return nil, err
            //  }
            //}
            logs.Logger.Debugf("Dail master redis server %s succeefully!", server)
            return c, err
        },
    }

When many connections coming redigo always random get errors like these:

[ERROR] [16:25:27] [NestPrepare @ class.go.29] GetName err: redigo: connection pool closed
[ERROR] [16:25:33] [NestPrepare @ class.go.29] GetName err: short write
[ERROR] [16:25:33] [NestPrepare @ class.go.29] GetName err: use of closed network connection
[ERROR] [16:25:33] [app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [16:25:33] [app.Rset error: redigo: unexpected type for Values, got type string
@garyburd
Copy link
Member

[ERROR] [16:25:27] [NestPrepare @ class.go.29] GetName err: redigo: connection pool closed

The application used a connection after closing the connection.

[ERROR] [16:25:33] [NestPrepare @ class.go.29] GetName err: short write

Concurrent writes to a connection can cause this error. See http://godoc.org/github.com/garyburd/redigo/redis#hdr-Concurrency for information on the concurrency allowed by Redigo.

 [ERROR] [16:25:33] [NestPrepare @ class.go.29] GetName err: use of closed network connection

I don't know what this error is. If you log the error type, I might be able to figure out what it is

[ERROR] [16:25:33] [app.Rset error: redigo: unexpected type for Values, got type string

The application is assuming that a string value returned by the server is a multi-bulk value.

@Icedroid
Copy link
Author

I get many many these errors, then my web application shut down. I need your help.Thank you very much.

[ERROR] [23:24:59] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:24:59] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:24:59] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:24:59] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:24:59] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:24:59] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:25:00] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:25:00] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string
[ERROR] [23:25:00] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string

But I restart my web application. It run good for sometime.After run for an hour or more than. Suddenly get these errors and it always got these errors writed to my log file. Can't get any response to my user.

@garyburd
Copy link
Member

 [ERROR] [23:25:00] [Prepare @ base.go.77] app.Rset error: redigo: unexpected type for Values, got type string

This error is caused by a bug in your application code. I cannot debug your application code from an error message.

@Icedroid
Copy link
Author

@garyburd Could you help me check my code. the main problem happen in the package models App.Rset() method.
https://github.com/Icedroid/MM_Api

@garyburd
Copy link
Member

Your application writes concurrently to a Redis connection. Concurrent writes are not supported.

@Icedroid
Copy link
Author

I am a golang newbie. Could you tell me how to change my code to use redis conn rightly.Could you give me some code how to rewrite my app.Rset() method?

@garyburd
Copy link
Member

As the documentation states, create the pool once. A request handler should get a connection from the pool and close the connection when the handler is done:

conn := pool.Get()
defer conn.Close()
// do something with the connection

I don't have time to write code for your application.

@Icedroid
Copy link
Author

I used it as you say. A controller when New a model will get a redis conn belong to this model and close it when this controller finished.

m.redis = RedisPool.Get()

@gomodule gomodule locked and limited conversation to collaborators Dec 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants