close the session only if it is open