mediocregopher / radix.v2

Redis client for Go
http://godoc.org/github.com/mediocregopher/radix.v2
MIT License
433 stars 92 forks source link

Driver crashes when receiving map[string]interface{} as attributes #11

Closed danbogos closed 8 years ago

danbogos commented 8 years ago

Hi,

I am a new user of the driver, many thanks for your efforts into it!

When converting from former driver into radix, have inherited some methods using map[string]interface{} for setting redis hashes.

Unfortunately this panics out. You can find bellow the trace and I can always reproduce it if you need me to test fixes,

Ta, DanB

panic: runtime error: index out of range

goroutine 22 [running]:
github.com/mediocregopher/radix.v2/redis.writeTo(0x7fb87475a108, 0xc8201e8310, 0xc8201ee000, 0x0, 0x80, 0xaed380, 0xc820205d90, 0x101, 0x17, 0x0, ...)
    /usr/local/goapps/src/github.com/mediocregopher/radix.v2/redis/resp.go:644 +0x324
github.com/mediocregopher/radix.v2/redis.writeTo(0x7fb87475a108, 0xc8201e8310, 0xc8201ee000, 0x0, 0x80, 0xad03a0, 0xc8201dff60, 0x101, 0x25, 0x0, ...)
    /usr/local/goapps/src/github.com/mediocregopher/radix.v2/redis/resp.go:676 +0x89f
github.com/mediocregopher/radix.v2/redis.(*Client).writeRequest(0xc82008c480, 0xc820049268, 0x1, 0x1, 0x0, 0x0)
    /usr/local/goapps/src/github.com/mediocregopher/radix.v2/redis/client.go:166 +0x542
github.com/mediocregopher/radix.v2/redis.(*Client).Cmd(0xc82008c480, 0xd2f2c0, 0x5, 0xc8201dff40, 0x2, 0x2, 0xad03a0)
    /usr/local/goapps/src/github.com/mediocregopher/radix.v2/redis/client.go:85 +0x12b
github.com/mediocregopher/radix.v2/pool.(*Pool).Cmd(0xc820175830, 0xd2f2c0, 0x5, 0xc8201dff40, 0x2, 0x2, 0x0)
    /usr/local/goapps/src/github.com/mediocregopher/radix.v2/pool/pool.go:95 +0x104
ipbxsuite/storage.(*RedisStorage).SetHEntity(0xc8200270e8, 0xd52520, 0xb, 0xc820205730, 0xc, 0xc820205740, 0x5, 0xc8201fd410, 0x0, 0x0)
    /usr/local/goapps/src/ipbxsuite/storage/hentity.go:39 +0x5c0
ipbxsuite/apier.(*ApierV1).NewSIPEndpoint(0xc8201ec830, 0xc820205730, 0xc, 0xc820205740, 0x5, 0xc820205750, 0x4, 0x0, 0x0, 0xc820205760, ...)
    /usr/local/goapps/src/ipbxsuite/apier/endpoint.go:74 +0x632
reflect.Value.call(0xbb7c20, 0xd1ef80, 0x13, 0xd2e718, 0x4, 0xc820049ee8, 0x3, 0x3, 0x0, 0x0, ...)
    /usr/local/go/src/reflect/value.go:432 +0x120a
reflect.Value.Call(0xbb7c20, 0xd1ef80, 0x13, 0xc820049ee8, 0x3, 0x3, 0x0, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:300 +0xb1
net/rpc.(*service).call(0xc8201f81c0, 0xc8200136c0, 0xc8201ecaf0, 0xc8201fed80, 0xc8201df000, 0xd0c5e0, 0xc8201e0f00, 0xd9, 0xac5840, 0xc820205830, ...)
    /usr/local/go/src/net/rpc/server.go:383 +0x1c1
created by net/rpc.(*Server).ServeCodec
    /usr/local/go/src/net/rpc/server.go:477 +0x4ac
mediocregopher commented 8 years ago

Hi dan! Would you be able to give me an example of the exact value that's being passed in and is causing the panic? I have tried encoding the value map[string]interface{}{"foo":true} on my own box and it works fine, and that would certainly hit the line you're getting the panic on.

danbogos commented 8 years ago

hi @mediocregopher,

Thanks for so fast feedback!

In the map there will be as values string, ints, bools and []byte (as part of serialization of objects). I think it is the []byte which produces the issue.

Here is a verbose log of what I am sending in the crash part:

HMSET, args: map[CGRAccount:DAN CGRRatingSubject:DAN RemoteAuthProxy:[123 34 72 111 115 116 34 58 34 49 55 50 46 49 54 46 50 53 52 46 49 48 49 34 44 34 80 111 114 116 34 58 48 44 34 84 114 97 110 115 112 111 114 116 34 58 34 34 125] E112:+4912345678901 CGRRequestType:rated RemoteDomain:172.16.254.101 RemoteAuthPassword:check123 RemoteCalledAlias:+4986517174963 DomainTag:itsyscom.com Tag:REP_1 UserTag:DAN1 AreaPrefix:8651 RemoteProxyId:main RemoteAuthUsername:cust_sua1 OwnCliOnTransfer:false RemoteUsername:cust_sua1 RemoteDisabled:false]

Let me know if additional info is required.

Ta, DanB

mediocregopher commented 8 years ago

should be fixed. Now that I see what the problem was, I'm not sure how it was never seen before tbh. Let me know if you have any other problems!

danbogos commented 8 years ago

hi @mediocregopher

Many thanks for this. I can confirm that it works like a charm now!

DanB