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
Fix race condition #1039
Fix race condition #1039
Conversation
I feel like automatically sending a followup when an exception is encountered isn't the right way to handle this. I also don't think this is an issue with the library itself, but rather just how Using the same example in the original issue but replacing the double |
Sending a followup when the interaction is already responded was also implemented before i made changes.
It was just an example. |
Can you provide an example that doesn't use |
I think you understood me wrong. My point was that there a good reasons for putting a response in a task and not awaiting it. |
Why? That’s a basic usage of asyncio. But for the sake of the question, you could replicate this behavior without explicitly using create_task in your specific code in several different ways. For example, if someone ran a slash command and your slash command code made a reference to another The problem is here: |
In my opinion catching the InteractionResponded exception is the best way to go here. A soloution that might also work is Add this method to InteractionResponse# Not sure about the name tho, maybe change it
async def respond_dynamic(self, *args, **kwargs):
try:
await self.send_message(*args, **kwargs)
except InteractionResponded:
# get followup webhook from parent
await self._parent.followup.send(*args, **kwargs) This still invoves the error catch but is a lot cleaner then my aproach catching the error in the context object. ApplicationContextJust retrun the method above in ApplicationContext.respond What are your thoughts about this aproach ? |
Regarding #1041 I did download Mihitoko fork and it still happens, so my issue lies elsewhere I'm pre sure. So, don't think application did not respond is not tied to this. |
Did you download fix_race_condtition branch? |
I used pip install git+https://github.com/Mihitoko/pycord.git and I still get the issue. I made sure I did pip uninstall py-cord first |
You need to add @fix_race_condition to that link. |
Merge conflicts here, please resolve. |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot a return and you might as well refactor respond
to just be an async function. It being a property was always a mistake
The core devs have been discussing this internally and this is actually part of our planned approach to tackle this. |
Co-authored-by: Jay Turner <jaynicholasturner@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These suggestions should turn this into an async function.
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor documentation/styling changes
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Summary
Fixes a race condition in interactions.py when two responses are made at the same time.
This PR fixes #963
Checklist
type: ignore
comments were used, a comment is also left explaining why