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

DiscordSocketClient fails to reconnect after Discord API outage #883

Closed
mmorz opened this issue Nov 18, 2017 · 3 comments
Closed

DiscordSocketClient fails to reconnect after Discord API outage #883

mmorz opened this issue Nov 18, 2017 · 3 comments

Comments

@mmorz
Copy link

mmorz commented Nov 18, 2017

Raspbian GNU/Linux 8.0 (jessie)
.NET Core 2.0
Discord.Net 1.0.2
Discord.Net.Commands 1.0.2

Debug level logs before disconnect

2017-11-18 00:21:14.101 +02:00 [Information] [Discord] Sent Heartbeat
2017-11-18 00:21:14.234 +02:00 [Information] [Discord] Received HeartbeatAck
2017-11-18 00:21:14.235 +02:00 [Information] [Discord] Latency = 150 ms
2017-11-18 00:21:55.356 +02:00 [Information] [Discord] Sent Heartbeat
2017-11-18 00:21:55.490 +02:00 [Information] [Discord] Received HeartbeatAck
2017-11-18 00:21:55.491 +02:00 [Information] [Discord] Latency = 130 ms
2017-11-18 00:22:00.237 +02:00 [Information] [Discord] Received Dispatch (PRESENCE_UPDATE)
2017-11-18 00:22:36.610 +02:00 [Information] [Discord] Sent Heartbeat
2017-11-18 00:22:36.746 +02:00 [Information] [Discord] Received HeartbeatAck
2017-11-18 00:22:36.747 +02:00 [Information] [Discord] Latency = 130 ms
2017-11-18 00:22:44.227 +02:00 [Information] [Discord] Received Dispatch (PRESENCE_UPDATE)
2017-11-18 00:22:55.198 +02:00 [Information] [Discord] Received InvalidSession
2017-11-18 00:22:55.199 +02:00 [Warning] [Discord] [Warning] Failed to resume previous session  Gateway
2017-11-18 00:22:55.204 +02:00 [Information] [Discord] Heartbeat Stopped
2017-11-18 00:22:55.205 +02:00 [Information] [Discord] Disconnecting
2017-11-18 00:22:55.205 +02:00 [Information] [Discord] Disconnecting ApiClient
2017-11-18 00:22:55.212 +02:00 [Information] [Discord] Waiting for heartbeater
2017-11-18 00:22:55.215 +02:00 [Information] [Discord] Waiting for guild downloader
2017-11-18 00:22:55.216 +02:00 [Information] [Discord] Clearing large guild queue
2017-11-18 00:22:55.216 +02:00 [Information] [Discord] Raising virtual GuildUnavailables
2017-11-18 00:22:55.216 +02:00 [Information] [Discord] Disconnected from Guild_1
2017-11-18 00:22:55.216 +02:00 [Information] [Discord] Disconnected from Guild_2
2017-11-18 00:22:55.216 +02:00 [Information] [Discord] Disconnected

No more logs after these. The client network connectivity was fine.

It seems that the client stops trying to reconnect to the API after disconnect like this. I think the client should persistently attempt to reconnect in all situations.

@JustArchi
Copy link

JustArchi commented Nov 18, 2017

I can confirm that this happened several times to me by now.

@foxbot
Copy link
Member

foxbot commented Nov 18, 2017 via email

foxbot added a commit that referenced this issue Jan 8, 2018
This resolves #883.

The previous behavior when the WebSocket was closed with a 4006
(invalid state) was to kill the reconnect task and log an exception.
While this behavior is 'correct', it does not make it obvious to the
user (or developer, in my case) as to why their client has just quit and
not bothered to attempt a reconnect.

The current best way to determine if the client needs to be reset is to
check that CloseCode property on the WebSocketException is set to 4006.
However, since Discord does not have close code 4006 documented, it
feels like only half of a solution.

This change allows users to opt-out of fatal invalid-states in the
client's configuration - though it is discouraged. If they have not
opted out of them, a 4006 will trigger a FatalException, which can then
be caught with a more simple pattern match in the Log event.

This change also expands what we consider to be a fatal close code, and
will raise a FatalException for a 1000 (Discord should never close a
connection for us), 4004 (invalid token), 4010/4011 (shard related).
foxbot added a commit that referenced this issue Jan 27, 2018
This resolves #938 and #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.
@foxbot
Copy link
Member

foxbot commented Jan 27, 2018

Resolved in 73ac9d7

@foxbot foxbot closed this as completed 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants