brianmario/mysql2 — pull request #378 by brianmario (2013-06-09 14:42:30+00:00)
Title: Track connection refcount to prevent GC races

In certain cases a Mysql2::Client and a Mysql2::Result may be freed in the same GC run. If the Client is freed before the Result a segv may occur when the Result tries to use the socket to make sure there isn't any more data to read before freeing itself. Since objects are freed in heap-order this issue was seemingly random, except on TravisCI.

Huge thanks to @evanphx for helping me track this one down and @rkh for helping with TravisCI since that's where the issue was finally reproducable.