fix the issue when connect refused, will throw a null pointer exception