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

MaxConcurrency failing to release #9995

Open
3 tasks done
rxnk opened this issue Nov 1, 2024 · 4 comments
Open
3 tasks done

MaxConcurrency failing to release #9995

rxnk opened this issue Nov 1, 2024 · 4 comments
Labels
needs info This issue needs more information to be actionable.

Comments

@rxnk
Copy link

rxnk commented Nov 1, 2024

Summary

The MaxConcurrencyReached exc is being raised no matter what

Reproduction Steps

It's usually happens on commands that are frequently used (high traffic) and happens randomly.

Minimal Reproducible Code

@bot.command()
@max_concurrency(1, BucketType.guild)
async def test(ctx):
  await asyncio.sleep(6)
  await ctx.send("test")

Expected Results

The concurrency is supposed to be released after the first use

Actual Results

The MaxConcurrencyReached error is being raised after the command has finished.

Intents

all

System Information

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

I've skimmed through the Semaphore class which this depends on and I determined this could be caused by a deadlock

@rxnk rxnk added the unconfirmed bug A bug report that needs triaging label Nov 1, 2024
@Rapptz Rapptz added needs info This issue needs more information to be actionable. and removed unconfirmed bug A bug report that needs triaging labels Nov 1, 2024
@Rapptz
Copy link
Owner

Rapptz commented Nov 1, 2024

The semaphore class is quite similar to the standard library's implementation so its usage should be quite similar and has been bug free for a while. It's hard to know how you're running into a deadlock so more information is needed.

@ju
Copy link

ju commented Nov 1, 2024

The semaphore class is quite similar to the standard library's implementation so its usage should be quite similar and has been bug free for a while. It's hard to know how you're running into a deadlock so more information is needed.

I've had the same issue for quite awhile. My temporary solution was writing an internal task to periodically check for specific commands with stuck semaphores and remove them manually.

I'm not sure how it's caused or how to really reproduce this and as @rxnk had mentioned, it is random and only happens on commands that are bound to potential spam or high usage.

For instance, I have a play command and have my max_concurrency set up this way: MaxConcurrency(1, per=BucketType.channel, wait=False).

Here's a code snippet of the command if necessary:

@hybrid_group(
    name="play",
    aliases=["p"], 
    max_concurrency=MaxConcurrency(1, per=BucketType.channel, wait=False),
)
async def play(self, ctx: Context, *, query: str):
    """
    Queue a track
    """
    tracks: Client = await ctx.voice.get_tracks(query, ctx=ctx)
    if not tracks:
        return await ctx.missing(f"No **results** found for `{query[:25]}`")

    await ctx.typing()
    
    if isinstance(tracks, Playlist):
        for track in tracks.tracks:
            await sleep(0)
            if track.length / 1000 >= 3600:
                continue 
            ctx.voice.queue.put(track)
        await ctx.send(f"Added **{len(tracks.tracks)} tracks** from [`{tracks.name}`]({tracks._uri})")
    else:
        track = tracks[0]
        track.requester = ctx.author
        ctx.voice.queue.put(track)
        await ctx.send(f"Added [`{track.title}`]({track}) to `{ctx.voice.queue._index(track)+1}` in the **queue**")

    ctx.voice.queue.recommended.clear()

    if not ctx.voice.is_playing:
        await ctx.voice.do_next()

I'm not sure exactly what information is needed but hopefully this helps and if more is needed, please let me know.

@rxnk
Copy link
Author

rxnk commented Nov 4, 2024

This has been problem since 2022 (#8071) which was on a completely different code structure but was never resolved.

@mikeshardmind
Copy link
Contributor

The issue you linked was never reproduced and there's no compelling reason to think this is a library issue with the available information in either their or your examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info This issue needs more information to be actionable.
Projects
None yet
Development

No branches or pull requests

4 participants