MrJoes/tornadio — pull request #36 by nanotone (2011-10-19 19:02:51+00:00)
Title: Prevent heartbeat leak when connection closed inside heartbeat callback

Whenever SocketConnection.close (and thus stop_heartbeat) is called from within _heartbeat -- either explicitly or due to an IOError -- the periodic callback will happily ignore this and schedule the next heartbeat. This causes a subtle memory and callback leak, which clogs up the IOLoop and negatively impacts performance.

This is easily prevented by checking the _running flag right before rescheduling the periodic callback.