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

Race condition in InteractionResponse #963

Closed
3 tasks done
Mihitoko opened this issue Feb 8, 2022 · 4 comments · Fixed by #1039
Closed
3 tasks done

Race condition in InteractionResponse #963

Mihitoko opened this issue Feb 8, 2022 · 4 comments · Fixed by #1039
Labels
unconfirmed bug A bug report that needs triaging

Comments

@Mihitoko
Copy link
Contributor

Mihitoko commented Feb 8, 2022

Summary

There is a race condition in InteractionResponse

Reproduction Steps

Running two task that will send a response to a Interaction will end in unexpected error.
Second Task will Raise NotFound Exception instead of InteractionResponded error.
This is due to a race condition in the libarry.

And because of this ApplicationContext.respond is also broken.

Minimal Reproducible Code

import asyncio

import discord.ext.commands

bot = discord.ext.commands.Bot()


@bot.slash_command(guild_ids=[...])
async def foo(ctx):
    async def respond():
        await ctx.respond("Race condition")

    asyncio.create_task(respond())
    asyncio.create_task(respond())


@bot.event
async def on_ready():
    print("Online")



bot.run("Token")

Expected Results

Command should exit with InteractionResponded or better ApplicationContext.respond should switch to followup.

Actual Results

NotFound HTTP exeption is raised.

404

Intents

Default

System Information

py-cord 2.0.0b4 master

Python 3.9 interpreter

OS Name Microsoft Windows 10 Home
Version 10.0.19041 Build 19041

Checklist

  • 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.

Additional Context

Started working on a fix using asyncio.Lock

@Mihitoko Mihitoko added the unconfirmed bug A bug report that needs triaging label Feb 8, 2022
@ephemeral8997
Copy link
Contributor

Your System Information should be your OS's information, py-cord's version info and more information if any. Also, can you show us the full exception traceback?

@TheShubhendra
Copy link

This happens with me also, when I run code in VS code python debugger using some breakpoints.

@Mihitoko
Copy link
Contributor Author

Mihitoko commented Feb 9, 2022

Your System Information should be your OS's information, py-cord's version info and more information if any. Also, can you show us the full exception traceback?

I'll recreate the bug when I'm in school.
And will update the issue with the requested information.

@Mihitoko
Copy link
Contributor Author

Mihitoko commented Feb 9, 2022

Your System Information should be your OS's information, py-cord's version info and more information if any. Also, can you show us the full exception traceback?

Traceback

Task exception was never retrieved
future: <Task finished name='Task-25' coro=<foo..respond() done, defined at C:\Users\redacted\PycharmProjects\pycord\tests\bot_test.py:10> exception=NotFound('404 Not Found (error code: 10062): Unknown interaction')>
Traceback (most recent call last):
File "C:\Users\redacted\PycharmProjects\pycord\tests\bot_test.py", line 11, in respond
await ctx.respond("Race condition")
File "C:\Users\redacted\PycharmProjects\pycord\discord\interactions.py", line 615, in send_message
await adapter.create_interaction_response(
File "C:\Users\redacted\PycharmProjects\pycord\discord\webhook\async_.py", line 192, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants