fix panic when connection fails