Skip to content

fix: guard against missing loop attribute in ConsoleMaster.done()#8166

Open
kaiisfree wants to merge 1 commit into
mitmproxy:mainfrom
kaiisfree:fix/console-done-loop-attr
Open

fix: guard against missing loop attribute in ConsoleMaster.done()#8166
kaiisfree wants to merge 1 commit into
mitmproxy:mainfrom
kaiisfree:fix/console-done-loop-attr

Conversation

@kaiisfree

Copy link
Copy Markdown

Summary

  • Initialize self.loop = None in ConsoleMaster.__init__() to prevent AttributeError when done() is called before running() completes
  • Guard self.loop.stop() with a None check in done()

Problem

When the console is started without a TTY (or running() fails for any reason before creating the urwid MainLoop), self.loop is never assigned. The subsequent call to done() then raises:

AttributeError: 'ConsoleMaster' object has no attribute 'loop'

Fix

Initialize self.loop = None in the constructor and add a guard before calling .stop() in done().

Fixes #8162

🤖 Generated with Claude Code

When running() fails before the urwid event loop is created,
self.loop is never assigned. This causes an AttributeError in
done() when it tries to call self.loop.stop().

Initialize self.loop = None and check before calling .stop().

Fixes mitmproxy#8162

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@lups2000 lups2000 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR :) There are some errors in the tests though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'ConsoleMaster' object has no attribute 'loop'

2 participants