Adds a test to reproduce PYTHON-649 and fixes it. Also adds docs and tests for some existing connection-management code.