Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
database/sql: segfault on NIL Rows.releaseConn() when context is cancelled #20160
I'm seeing reproducible segmentation faults in
This looks like a race condition where the
I tested with
An interesting observation is that the bug seems to coincide with the use of prepared statements no matter if a statement is reused across connections or limited to a DB connection and closed right after use. I havent' seen the bug surface without prepared statements, but maybe I was just not patient enough. Here's how different types of queries behave:
Here's how to reproduce the issue:
For a little more context, I inserted a debug statement in sql.go right before the problematic line (returning from here proved to be a quick workaround, but I'm not sure of the consequences).
and got this output (formatted)
I was surprised to see that many open statements on the connection, in particular, because I had prepared and reused a single statement across all connections without closing it. However, this looks like a separate issue to me.
What version of Go are you using (
Thanks for the detailed and reproducible error report. I'm impressed.
This is a common misconception. A single statement will still pull an arbitrary connection from the connection pool, and if not prepared on that connection, re-prepare it. It is unfortunate that is assumes all databases tie statements to connections, but it does (this is sometimes true, but not for all). In other words, I would expect to see as many as 20 prepare commands issued per statement in this example.