Safely close TLS connections.
Catch IOExceptions only when closing connections.