Address shutdown behavior #6633
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!6633
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/dry-run"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Analysis of the problem
Problem Analysis
Based on the error traceback and codebase investigation, here's what's happening:
The Error
This error occurs during the bot shutdown process when red.close() is called. The issue is that the Red class (which inherits from discord.ext.commands.AutoShardedBot) is trying to access an internal attribute __queue that doesn't exist.
Root Cause
The problem stems from the mixin initialization order in the Red class:
Looking at the initialization chain:
Red.init (line 104-241 in bot.py) does extensive setup work BEFORE calling super().init() at line 241
RPCMixin.init (line 144-146 in _rpc.py) calls super().init(**kwargs)
commands.GroupMixin doesn't define init, so it passes through
Finally reaches AutoShardedBot.init which sets up internal attributes like __queue
The issue is that during the --dry-run execution:
The bot starts initialization
At line 366 in main.py, when --dry-run is detected, it calls sys.exit(ExitCodes.SHUTDOWN)
This triggers the shutdown handler at line 539
The shutdown handler calls await red.close() at line 441
But red.close() → super().close() (line 2278 in bot.py) tries to access AutoShardedClient's internal __queue attribute
This attribute was never properly initialized because the initialization was interrupted
Why This Happens Specifically with --dry-run
The --dry-run flag causes an early exit at line 365-366 in main.py:
This happens before await red.start(token) is called (line 369), which means:
The bot's connection lifecycle never begins
Discord.py's internal sharding infrastructure (including __queue) is never fully initialized
But the shutdown handler still tries to call close() which expects these internals to exist
try, catch might not be the best solution but I can't think of a better one. This only happens when it is not fully initialized and thus sharding is not possible.
closes #6572
the original issue is also addressed.
This will be fixed by the next discord.py update:
https://github.com/Rapptz/discord.py/pull/10422
Pull request closed