By using a single instance of a help command and doing preparation work (including assigning of context) to said single instance while also relying on that in other places , the help formatter is subject to race conditions.
Have a bot under heavy load such that if 2 help commands are issued at the same time, it's possible for results to not end up truly FIFO due to channel based ratelimits. and context switching with asyncio
All prep work would be kept separate per invoke, including keeping context correct.
I have searched the open issues for duplicates.
I have shown the entire traceback, if possible.
I have removed my token from display, if visible.
discord.py version: 1.0.1
Python version: 3.7.2
Operating system: Windows, for testing, but can confirm this is not system specific.
The text was updated successfully, but these errors were encountered:
Personally I haven't experience this issue in both the original HelpFormatter and the new HelpCommand. Both HelpFormatter and HelpCommand were single-instances in their design. However I understand that it is possible on a theoretical basis. There are a few ways to fix it as far as I'm concerned:
Use contextvars to fix the context issue.
This opens up another problem, in that every other attribute is no longer safe.
Contextvars requires 3.6+ to be supported while the lib is currently 3.5.3+ due to dependencies so it'd be breaking.
Pass the Context around in every callable that needs it.
Again, this fixes the underlying problem with the Context but not with every other attribute.
This is a rather large breaking change for consumers.
Copy the instance when necessary and run the functions on that copy.
This one fixes the above issues but it's still a breaking change if someone expected the instances to maintain state throughout the whole ordeal. However, it's probably not as big of a breaking change as the other two solutions.
Personally if I were to fix this I'd use the 3rd solution and swallow the minor breakage that was not explicitly documented anywhere.
Slight breaking change if someone had an expectation that no copies
were made behind the scene (which is sensible), however writing code
that relies on this expectation is probably buggy anyway.