8000 No more NREs when disposing/finalizing, fixes #1547 by Kaoticz · Pull Request #1567 · DSharpPlus/DSharpPlus · GitHub
[go: up one dir, main page]

Skip to content

No more NREs when disposing/finalizing, fixes #1547#1567

Merged
akiraveliara merged 3 commits intoDSharpPlus:masterfrom
Kaoticz:GC-NRE
Jun 13, 2023
Merged

No more NREs when disposing/finalizing, fixes #1547#1567
akiraveliara merged 3 commits intoDSharpPlus:masterfrom
Kaoticz:GC-NRE

Conversation

@Kaoticz
Copy link
Contributor
@Kaoticz Kaoticz commented Jun 8, 2023

Summary

Fixes bug #1547

Details

I removed finalizers while adding null guards to Dispose methods. I used ripgrep to find all finalizers in the project (rg "\~(\S+)\(\)" *) and addressed them one by one. I was concerned about removing the finalizers from DiscordWebhookClient and DiscordShardedClient because they are doing more than just disposing resources and since I didn't want to risk introducing any breaking change, I decided to leave them alone.

These changes were tested with the bot in DSharpPlus.Test and also my personal Discord bot, both having run perfectly fine. The scenario I was encountering does not occur anymore, even after several garbage collections.

Changes proposed

  • No more exceptions thrown inside the garbage collector.

Notes

Some classes contain Dispose methods, despite not implementing the IDisposable interface. I wrote a comment for those, since I didn't want to change the API of the library in a simple bug fix, but if you want, I can implement the interface before the PR is accepted.

@Kaoticz
Copy link
Contributor Author
Kaoticz commented Jun 10, 2023

This should be ready for merging. If anyone feels like doing their own testing, feel free to do so.

@akiraveliara
Copy link
Member

thank you! - my apologies that i didn't get to it in time

@akiraveliara akiraveliara merged commit 88bfbcb into DSharpPlus:master Jun 13, 2023
akiraveliara pushed a commit that referenced this pull r 8000 equest Jun 13, 2023
* Fixed NREs when disposing/finalizing..

* Some additional safeguards, just in case

* Prevent disposed sharded clients from throwing InvalidOperationException in the GC
@Kaoticz Kaoticz deleted the GC-NRE branch June 13, 2023 17:00
OoLunar pushed a commit that referenced this pull request Oct 3, 2024
* Fixed NREs when disposing/finalizing..

* Some additional safeguards, just in case

* Prevent disposed sharded clients from throwing InvalidOperationException in the GC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0