Add support for closing the connection automatically on disconnect