Stop the JS long polling reconnect loop if in the incorrect state

#2125
Merge branch 'release' into dev