fix typo
add error case and close socket on error