only close socket if it exists, fix #89