go-xorm / xorm

Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
BSD 3-Clause "New" or "Revised" License
6.67k stars 754 forks source link

在一些特定的情况下Close会报空引用 #1176

Open wenbingzhang opened 5 years ago

wenbingzhang commented 5 years ago
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x648e82]

goroutine 1 [running]:
...github.com/go-xorm/xorm.(*Engine).Close(0x0, 0x7, 0x7f3273cd2390)
    .../github.com/go-xorm/xorm/engine.go:318 +0x22

在特定的环境下会报空引用,建议在Close()下加上空引用检查

lunny commented 5 years ago

Could you show how did you use Engine and Engine.Close?

wenbingzhang commented 5 years ago

你能说明你是如何使用Engine和。Engine关闭的吗?

linux

cat /etc/sysctl.conf | grep -v -e "^#" -e "^$"
fs.file-max = 1024

打开最大文件数比较小,并发超过的时候会出现这个问题。

lunny commented 5 years ago

Please show codes about how you are using Engine here.

wenbingzhang commented 5 years ago

Please show codes about how you are using Engine here.

1、在main中我使用了 defer engine.Close(),然后10个协程并发处理数据库。其他的就是正常的增删改查了。 2、没有显示使用engine.NewSession()方法。 3、没在main以外的任何地方使用engine.Close() 4、当时我还在用其他程序测试多线程并发,线程数超过了fs.file-max=1024的值。