Don't setTimeout unless reconnecting is true. Then you can remove the `if (reconnecting)` inside the function.