google-app-enginegoredislabs

Google App engine-Redislabs Go runtime production error - invalid memory address or nil pointer dereference


I'm using the Redis Cloud service (from Redis Labs) on Google App engine Go Runtime , and I get the above mentioned error when I try getting a key that doesn't exist. The code works fine on the local test server, but panics in production.

 c, err := redis.Dial("tcp", "pub-redis-myredis:<myport>")
_, err = c.Do("AUTH", "password") 
value, err := c.Do("GET", "foo4")

if value == nil {
    log.Infof(contextOfAppEngineWhereServerIsRunning, "value not found in redislabs")

} 

The log shows that the panic is in the line _, err = c.Do("AUTH", "password")


Solution

  • On AppEngine your application (webapp) runs in a sandboxed environment where you can't use the standard net package for sockets (which I assume redislabs use).

    You have to use the appengine/socket package for outbound network sockets.

    It most likely works locally because the restriction only applies in production environment.

    Always check returned error values. Currently in the code you posted you check none. Should you have checked it, you would see the cause from the error.

    You get invalid memory address or nil pointer dereference error because your first call fails:

    c, err := redis.Dial("tcp", "pub-redis-myredis:<myport>")
    

    err will be a non-nil value and c is nil which means you can't call it's Do() method.