seefan / gossdb

ssdb client for go with pool surport
MIT License
131 stars 47 forks source link

连接池问题 #42

Closed changtsing closed 6 years ago

changtsing commented 6 years ago

问题描述, 初始化连接池,暂时不从连接池里面获取链接,指定错误的ip或者端口,程序崩溃

panic: runtime error: index out of range

goroutine 3 [running]: github.com/seefan/gossdb/vendor/github.com/seefan/gopool.(Slice).checkMinPoolClient(0xc420098550, 0x3c) /home/wangchangqing/work/tuser/tuser-center/src/github.com/seefan/gossdb/vendor/github.com/seefan/gopool/watch.go:56 +0x2d5 github.com/seefan/gossdb/vendor/github.com/seefan/gopool.(Pool).watch(0xc420126380) /home/wangchangqing/work/tuser/tuser-center/src/github.com/seefan/gossdb/vendor/github.com/seefan/gopool/watch.go:16 +0x149 created by github.com/seefan/gossdb/vendor/github.com/seefan/gopool.(*Pool).Start /home/wangchangqing/work/tuser/tuser-center/src/github.com/seefan/gossdb/vendor/github.com/seefan/gopool/pool.go:95 +0x17b exit status 2

查看代码

if checkIndex < 0 || checkIndex < s.current {
    checkIndex = s.length - 1
}
//同一个连接检查要间隔HealthSecond秒
if s.pooled[checkIndex] != nil && !s.pooled[checkIndex].isUsed && s.pooled[checkIndex].lastTime+hs < now {
    s.pooled[checkIndex].lastTime = now
    if !s.pooled[checkIndex].Client.Ping() {
        s.pooled[checkIndex].Client.Close()
        if err := s.pooled[checkIndex].Client.Start(); err != nil {
            s.length -= 1
        }
    }
}

checkIndex=-1,导致的崩溃, 这块是不是对checkIndex在加一层判断