Fix order of operations on CLOSE_CONNECTION flag