Golang,PostgreSQL的rows.next()恐慌

I'm getting error when interating rows using rows.next() using postgresql in golang. This is only happens in several machines and in quite unpredictable timing, which make it difficult to debug.

panic: runtime error: index out of range [recovered]
        panic: runtime error: index out of range

goroutine 28078 [running]:
panic(0xa63ae0, 0xc420014090)
        /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/lib/pq.(*conn).errRecover(0xc420780500, 0xc420d2ef28)
        /share/dpkg-build/pacman-build/src/github.com/lib/pq/error.go:482 +0x57e
panic(0xa63ae0, 0xc420014090)
        /usr/local/go/src/runtime/panic.go:458 +0x243
github.com/lib/pq.binaryDecode(0xc420780728, 0xc4207806f0, 0x0, 0x30, 0xc400000017, 0xa24300, 0xc421fcb4b0)
        /share/dpkg-build/pacman-build/src/github.com/lib/pq/encode.go:76 +0x385
github.com/lib/pq.decode(0xc420780728, 0xc4207806f0, 0x0, 0x30, 0x17, 0x1, 0xa24300, 0xc421fcb4b0)
        /share/dpkg-build/pacman-build/src/github.com/lib/pq/encode.go:61 +0x6c
github.com/lib/pq.(*rows).Next(0xc42281e310, 0xc420b82000, 0x2f, 0x2f, 0x0, 0x0)
        /share/dpkg-build/pacman-build/src/github.com/lib/pq/conn.go:1369 +0x420
database/sql.(*Rows).Next(0xc42005b560, 0xc4204eb590)
        /usr/local/go/src/database/sql/sql.go:1758 +0x6c
github.com/xxxxx/yyyyy/src/product/elasticsearch.getPart1(0xc4204eb590, 0xa24300, 0xc420a04190, 0x0, 0x0) <-- rows.next() here
        /share/dpkg-build/pacman-build/src/github.com/xxxxxx/yyyyyy/src/product/elasticsearch/collector.go:71 +0xff
github.com/xxxxx/yyyyy/src/product/elasticsearch.Get(0xa24300, 0xc420a04190, 0xc420a04190, 0xa24300, 0xc420a04190, 0xc420980a00)
        /share/dpkg-build/pacman-build/src/github.com/xxxxxx/yyyyyy/src/product/elasticsearch/collector.go:29 +0x118

From the call-stack above the panic comes from binaryDecode function which I imagine explain why it's only happening in some machines. There might be some bad network package or the message got corrupted, so the driver couldn't decode the message then failing.

However I don't know where to go after this, anyone has idea?

Thanks

The driver expects a 4 byte slice to encode as an integer, but is panicking when trying to index the individual bytes.

Could the data accidentally be nil, or a data type less than 4 bytes?

In the driver github.com/lib/pq/encode.go:

case oid.T_int4:
    return int64(int32(binary.BigEndian.Uint32(s)))

In encoding/binary Uint32 (this line panics with index out of bounds):

return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24