Here at VividCortex, we’re huge fans of the Go language and its
database access library,
database/sql. As you’ve
probably seen firsthand, the surface area of
database/sql is pretty small, but there’s a lot you
can do with it. That includes plenty of risk for error and
deceptive mistakes. This blog post is dedicated to some
of the past mistakes we’ve made ourselves, in hopes that you
won’t also make them when the time comes.
Deferring inside a loop. A long-lived
function with a query inside a loop, and defer
rows.Close()inside the loop, will cause both memory and connection usage to grow without bounds.