Close api connections before state.