fix error handling issues for tls sockets