Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect() after InvalidSession might be not working #938

Closed
SubZero0 opened this issue Jan 22, 2018 · 3 comments
Closed

Reconnect() after InvalidSession might be not working #938

SubZero0 opened this issue Jan 22, 2018 · 3 comments
Labels

Comments

@SubZero0
Copy link
Member

SubZero0 commented Jan 22, 2018

After the recent discord issue, all my Discord.Net bots didn't reconnect. some screenshots:
dnet
armdabot

The common between them was the "Failed to resume previous session" before disconnecting and staying like that.

Looking through the source, I saw _connection.Reconnect(); //TODO: Untested
https://github.com/RogueException/Discord.Net/blob/a384ce02abcca096cb99d55f7ba9b52c2ec48148/src/Discord.Net.WebSocket/DiscordSocketClient.cs#L421

So I thought about trying to simulate Discord sending an InvalidSession opcode with the following code:

        private async Task TryToKill()
        {
            Console.WriteLine("TRY TO KILL INITIALIZING");
            await Task.Delay(5000);
            Console.WriteLine("TRY TO KILL");
            Type type = AppDomain.CurrentDomain.GetAssemblies().First(x => x.GetName().Name == "Discord.Net.WebSocket").GetType("Discord.API.Gateway.GatewayOpCode");
            object enumValue = Enum.ToObject(type, 9);

            MethodInfo dynMethod = _client.GetType().GetMethod("ProcessMessageAsync", BindingFlags.NonPublic | BindingFlags.Instance);
            dynMethod.Invoke(_client, new object[] { enumValue, null, null, false });
            Console.WriteLine("DONE");
        }

What I did was changing the "payload" (the bool inside the Invoke). These are the results:

With false (sends an Identify):
false
It reconnects succesfully.

With true (calls Reconnect()):
true
It justs disconnects and stays like that.

I don't really know much about how the ConnectionManager works, but I'm assuming Reconnect() isn't doing it's job and leaves it in that idle disconnected state and causing what happens at #883

@Bitl
Copy link

Bitl commented Jan 22, 2018

Use this while we wait for an update:
https://gist.github.com/foxbot/7d81edab4e36497c643828638af289b8

@SubZero0
Copy link
Member Author

SubZero0 commented Jan 22, 2018

@Bitl I know about that and I'm already doing something similar. I'm trying to find what causes it and Reconnect() might be the one (or one of them) to be blamed.

@SubZero0 SubZero0 changed the title Reconnect after InvalidSession might be not working Reconnect() after InvalidSession might be not working Jan 22, 2018
@foxbot
Copy link
Member

foxbot commented Jan 25, 2018

This looks like the problem from my findings as well.

I have a patch running on my testing bots right now to test, just waiting on the next Discord outage to be sure.

@foxbot foxbot added the bug label Jan 25, 2018
@foxbot foxbot closed this as completed in 73ac9d7 Jan 27, 2018
FiniteReality pushed a commit to FiniteReality/Discord.Net that referenced this issue May 5, 2018
This resolves discord-net#938 and discord-net#883

Note: This fix is not 'verified' in production (I waited over a week for
another full Discord outage and never encountered one), but I do have it
on record from b1nzy that Discord may send an OP9 with `{"d": true}`
during outages, so this would appear to be the proper fix.

The removed code seems to have been leftover from when ConnectionManager
was rewritten and never finished.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants