Make sure connect will be closed and memory be free
Close connect util write stream finish
try to shutdown before close connect