improve socket error handling