SERVER-10261 end TCP sockets cleanly

This is a partial backport of SERVER-9041's commit.  In particular, this fixes an issue with
SSL and the Java driver's session caching.