出错代码

type Member struct {
    ID    int    `json:"id"`
    Phone string `json:"phone"`
}

rs := []Member{}
s := " SELECT * FROM members WHERE  group_id = 101 AND deleted = 0 AND phone IN (?)  "
err := db.MemberDB.Debug().Raw(s, phones).Scan(&rs).Error

错误信息(难以复现,有时运行几小时才出错,有时第一遍错误)

[mysql] 2019/12/09 18:19:09 packets.go:72: read tcp 192.168.8.130:39500->*.*.*.*:3306: read: connection timed out
[mysql] 2019/12/09 18:19:09 packets.go:393: busy buffer

(/home/rui/workplace/go/src/order-service/cmd/import_old_order/main.go:228) 
[2019-12-09 18:19:09]  invalid connection 

(/home/rui/workplace/go/src/order-service/cmd/import_old_order/main.go:228) 
[2019-12-09 18:19:09]  [151085.87ms]    SELECT * FROM members where group_id = 101 and deleted = 0 and phone in ('189******','150*********','153******')    
[1 rows affected or returned ] 
panic: invalid connection

我一直以为是mysql 连接问题,后来 当我把 'SELECT * ' 替换为 'SELECT id, phone ' 正常运行 (SELECT * 会有几十个字段) 猜测是 Scan 时, buffer 问题

gorm : 1.9.11 github.com/go-sql-driver/mysql v1.4.1 mysql :5.7

Comment From: github-actions[bot]

This issue will be automatically closed because it is marked as GORM V1 issue, we have released the public testing GORM V2 release and its documents https://v2.gorm.io/docs/ already, the testing release has been used in some production services for a while, and going to release the final version in following weeks, we are still actively collecting feedback before it, please open a new issue for any suggestion or problem, thank you

Also check out https://github.com/go-gorm/gorm/wiki/GORM-V2-Release-Note-Draft for how to use the public testing version and its changelog

Comment From: counten

gorm.io/gorm v1.21.10 ,Postgresql 数据库遇到类似问题,read tcp sourceIP:12480->targetIP:5432: read: connection timed out,但报错未提示 busy buffer。