Fix connection close problems