gpt4 book ai didi

sql - Golang,postgresql rows.next() panic

转载 作者:数据小太阳 更新时间:2023-10-29 03:25:53 25 4
gpt4 key购买 nike

在 golang 中使用 postgresql 使用 rows.next() 对行进行交互时出现错误。这只发生在几台机器上,而且时间相当不可预测,这使得调试变得困难。

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

从上面的调用堆栈中, panic 来自 binaryDecode 函数,我想这可以解释为什么它只发生在某些机器上。可能有一些错误的网络包或消息已损坏,因此驱动程序无法解码消息然后失败。

但是我不知道之后该去哪里,有人有想法吗?

谢谢

最佳答案

驱动程序希望将 4 字节的 slice 编码为整数,但在尝试索引单个字节时却感到 panic 。

数据会不会意外为 nil,或小于 4 字节的数据类型?

在驱动程序中github.com/lib/pq/encode.go :

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

在编码/二进制中 Uint32 (这一行因索引越界而 panic ):

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

关于sql - Golang,postgresql rows.next() panic ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42047991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com