flike / kingshard

A high-performance MySQL proxy
6.41k stars 1.23k forks source link

"handleQuery" "runtime error: invalid memory address or nil pointer dereference" #414

Open StdioA opened 6 years ago

StdioA commented 6 years ago

使用 hash 模式进行 shard 时,根据 shard key 进行查询(或删除)操作时会报错,报错信息如下:

2018/02/04 13:04:20 - Error - err:runtime error: invalid memory address or nil pointer dereference,sql:select * from user_log where user_id=1
2018/02/04 13:04:20 - ERROR - conn_query.go:[44] - [ClientConn] "handleQuery" "runtime error: invalid memory address or nil pointer dereference" "stack=goroutine 1001 [running]:
github.com/flike/kingshard/proxy/server.(*ClientConn).handleQuery.func1(0xc420395dd0)
    /go/src/github.com/flike/kingshard/proxy/server/conn_query.go:42 +0x1f0
panic(0x7c6340, 0xa586e0)
    /usr/local/go/src/runtime/panic.go:491 +0x283
github.com/flike/kingshard/proxy/server.(*ClientConn).buildSelectOnlyResult(0xc42013a240, 0xc420244018, 0x1, 0x1, 0xc42016e000, 0x0, 0x2000107, 0x0)
    /go/src/github.com/flike/kingshard/proxy/server/conn_select.go:391 +0x4b
github.com/flike/kingshard/proxy/server.(*ClientConn).mergeSelectResult(0xc42013a240, 0xc420244018, 0x1, 0x1, 0xc42016e000, 0x0, 0xc420244018)
    /go/src/github.com/flike/kingshard/proxy/server/conn_select.go:143 +0x64
github.com/flike/kingshard/proxy/server.(*ClientConn).handleSelect(0xc42013a240, 0xc42016e000, 0x0, 0x0, 0x0, 0x0, 0xc420395d78)
    /go/src/github.com/flike/kingshard/proxy/server/conn_select.go:130 +0x1f2
github.com/flike/kingshard/proxy/server.(*ClientConn).handleQuery(0xc42013a240, 0xc4202c6091, 0x2e, 0x0, 0x0)
    /go/src/github.com/flike/kingshard/proxy/server/conn_query.go:74 +0x50e
github.com/flike/kingshard/proxy/server.(*ClientConn).dispatch(0xc42013a240, 0xc4202c6090, 0x2f, 0x2f, 0x0, 0x0)
    /go/src/github.com/flike/kingshard/proxy/server/conn.go:306 +0x4a5
github.com/flike/kingshard/proxy/server.(*ClientConn).Run(0xc42013a240)
    /go/src/github.com/flike/kingshard/proxy/server/conn.go:276 +0x7f
github.com/flike/kingshard/proxy/server.(*Server).onConn(0xc42014c100, 0xa2b2c0, 0xc42000e028)
    /go/src/github.com/flike/kingshard/proxy/server/server.go:363 +0x1bd
created by github.com/flike/kingshard/proxy/server.(*Server).Run
    /go/src/github.com/flike/kingshard/proxy/server/server.go:608 +0x12f
|sql=select * from user_log where user_id=1" conn_id=0

shard 配置信息如下:

schema:
  nodes: [node-default, node-shard-1, node-shard-2]
  default: node-default
  shard:
  - db: ckin
    table: user_log
    key: user_id
    nodes: [node-shard-1, node-shard-2]
    type: hash
    locations: [32, 32]
flike commented 6 years ago

能否提供一个更简单的复现case?例如建几张表,就可以出现?对应的建表SQL,kingshard配置,麻烦贴一下。我好继续跟进。谢谢