Fix shutdown issue for ConnectionFactory