Skip to content

Fixed a potential WebSocketException crash that would print to console without getting logged by the logger first.#338

Open
AraHaan wants to merge 2 commits intoNetCordDev:alphafrom
AraHaan:fixes/fix-potential-websocketexception-crash
Open

Fixed a potential WebSocketException crash that would print to console without getting logged by the logger first.#338
AraHaan wants to merge 2 commits intoNetCordDev:alphafrom
AraHaan:fixes/fix-potential-websocketexception-crash

Conversation

@AraHaan
Copy link
Copy Markdown

@AraHaan AraHaan commented May 2, 2026

This fixes a potential WebSocketException crash that would print to console without getting logged via the logger when the user just so happens to lose internet (say router gets rebooted by ISP) right when Discord wants ResumeAsync to be called. This also fixes the issue at startup as well where the user unfortunately gets hit by this as soon as they start their bot, but just before any attempt is made to connect to discord (there is a small window between Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) and NetCord.Gateway.GatewayClient.StartAsync(PresenceProperties presence, CancellationToken cancellationToken) prior to the call to StartAsync in WebSocketClient.

The fix here is to instead log the exceptions via the logger before rethrowing.

…onsole without getting logged via the logger when the user just so happens to lose internet (say router gets rebooted by ISP) right when Discord wants ``ResumeAsync`` to be called. This also fixes the issue at startup as well where the user infortunately gets hit by this as soon as they start their bot, but just before any attempt is made to connect to discord (there is a small window between ``Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)`` and ``NetCord.Gateway.GatewayClient.StartAsync(PresenceProperties presence, CancellationToken cancellationToken)`` prior to the call to ``StartAsync`` in WebSocketClient.

The fix here is to instead log the exceptions via the logger.
@AraHaan AraHaan changed the title Fix a potential WebSocketException crash that would print to console without getting logged by the logger first. Fixed a potential WebSocketException crash that would print to console without getting logged by the logger first. May 2, 2026
@AraHaan AraHaan marked this pull request as ready for review May 2, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant