go
runtime_error
ai_generated
true
sql: Rows are closed
ID: go/database-sql-rows-closed
80%Fix Rate
87%Confidence
0Evidence
2024-01-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.15 | active | — | — | — |
| 1.20 | active | — | — | — |
Root Cause
Attempting to call Next() or Scan() on a sql.Rows object after it has been closed, either explicitly or due to an error.
generic中文
在 sql.Rows 对象已关闭后(显式关闭或由于错误)尝试调用 Next() 或 Scan()。
Workarounds
-
95% success
Always check errors and call rows.Close() in defer: defer rows.Close(); for rows.Next() { ... } -
90% success
Check rows.Err() after iteration: if err := rows.Err(); err != nil { handleErr(err) }
Dead Ends
Common approaches that don't work:
-
90% fail
Rows are already closed; further calls will panic or return stale data.
-
60% fail
May cause data inconsistency and resource leaks if not handled properly.