Only close connection when not doing something else