Go语言·操作MySQL出现404 Not Found
Golang·操作MySQL出现 runtime error: invalid memory address or nil pointer dereference
http: panic serving 127.0.0.1:59845: runtime error: invalid memory address or nil pointer dereference goroutine 2377 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1825 +0xbf panic({0x12820c0, 0x14bb900}) /usr/local/go/src/runtime/panic.go:844 +0x258 database/sql.(*Rows).Next(0x0) /usr/local/go/src/database/sql/sql.go:2985 +0x27 golang/life.QueryLife_data({0x12c333b, 0x9}, {0x12c42c6, 0xc}, {0xc00018c339, 0x4}, {0xc00018c345, 0x2}) /Volumes/Linwute/项目/Golang/life/query_Life.go:175 +0x256 main.getLifeListQuery({0x133de10, 0xc000a542a0}, 0xc000a50300) /Volumes/Linwute/项目/Golang/main.go:42 +0x1a7 net/http.HandlerFunc.ServeHTTP(0x0?, {0x133de10?, 0xc000a542a0?}, 0x10625d6?) /usr/local/go/src/net/http/server.go:2084 +0x2f net/http.(*ServeMux).ServeHTTP(0x0?, {0x133de10, 0xc000a542a0}, 0xc000a50300) /usr/local/go/src/net/http/server.go:2462 +0x149
原因很简单:
如代码中第10行 :/Volumes/Linwute/项目/Golang/life/query_Life.go:175 +0x256
其就是175行 出问题,根本原因是数据库链接池过大,没有关闭数据库导致。
在数据库操作代码结束加上如下:
rows.Close() //关闭结果集(释放连接
Db.Close() //关闭数据库
必须关闭Db.Close关闭数据库 否则并发连接池过大,请求超50次会导致数据库宕机404或502
928 Views