highfidelity/hifi — pull request #2407 by ZappoMan (2014-03-20 21:50:40+00:00)
Title: fix voxel server crash/pure virtual call on shutdown of client

I was able to repro this bug by writing a bot script that shut down at random intervals and then running a ton of these bots. The problem was that if the sending thread was active, while the OctreeQueryNode object is in the process of being deleted, there were a few pure virtual functions that might be called (namely to get the packet type for this particular type of server/sender). You can't call pure virtual functions while the object is being torn down.

There's two parts to the fix. The first is to store the packet type on init, since that can't change after the node data and the threads have been started... so we can store the value, and use that, therefore eliminating the calls to pure virtual functions.

The second part of the fix is to also add an _isShuttingDown to the OctreeQueryNode, and to make sure that all functions of OctreeQueryNode and most all functions of OctreeSendThread check to see if the node is shutting down, if it is shutting down, then exit all ops as quickly as possible. This allows the sending thread to wind down much more quickly, and stop doing unneeded work.