Correctly close connection when requested.