You only need to call `_socket = undefined;` inside of `if (_socket)` block.