This sometimes happens when the client can't handle logging in to a area with a lot of items around, or generally when it needs to receive a lot of data during the login process and can't handle it.
It can also happen if you hit the Enter/Return key too fast while logging in (most common cause in my case).