Skip to content

Conversation

@woutdenolf
Copy link

@woutdenolf woutdenolf commented Aug 16, 2025

Closes #1449

When starting flower with --port=0 the port is dynamically assigned but print_banner shows Visit me at http://0.0.0.0:0.

  • Fix by passing the flower app to print_banner instead of the celery app.
  • For this to work we need to decouple the start of the server and the start of the event loop. We know the port only after the server was started. In addition the event loop might need to be controlled outside of this class. In the unit test framework for example. So the decoupling is useful for that as well.
  • For backward compatibility the coupled start method is kept (same for stop)
    class Flower(tornado.web.Application):
        ...
        def start(self):  # for backward compatibility
            self.start_server()
            self.update_workers()
            self.serve_forever()
  • To add a unit test for the dynamic port showing up in the banner, the AsyncHTTPTestCase base class needs to be in charge of creating the HTTP server. Before it was tornado.testing.AsyncHTTPTestCase doing this. Now we derive from tornado.testing.AsyncTestCase and let Flower handle the HTTP server. This happens in production anyway so now we cover that as well. In addition this makes the usage in other tests much cleaner.


print_banner(self._app)

self.assertIn(f'INFO:flower.command:Visit me at http://0.0.0.0:{port}', cm.output)
Copy link
Author

Choose a reason for hiding this comment

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

This is the unit test for the dynamic port number showing up in the banner.

@woutdenolf woutdenolf force-pushed the log_dynamic_port branch 2 times, most recently from 3b07ff0 to 78ddaa6 Compare August 16, 2025 21:17
@auvipy auvipy requested review from auvipy and Copilot August 17, 2025 04:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where the banner displayed incorrect port information (showing port 0) when Flower is started with dynamic port allocation (--port=0). The solution refactors the print_banner function to receive the Flower app instance instead of the Celery app, allowing it to access the actual bound port.

Key changes:

  • Decoupled server startup from event loop execution to determine the actual port before printing the banner
  • Modified print_banner to accept Flower app instance and retrieve dynamic port information
  • Refactored test base class from AsyncHTTPTestCase to AsyncTestCase for better control over HTTP server lifecycle

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
flower/command.py Updated to separate server startup from event loop and pass Flower app to print_banner
flower/app.py Added methods for server lifecycle management and URL generation with dynamic port support
tests/unit/init.py Refactored base test class to manage HTTP server directly instead of using Tornado's built-in server
tests/unit/test_command.py Updated tests to use new banner function signature and added dynamic port test
tests/unit/views/*.py Updated to use self._app instead of self.app following test base class changes
tests/unit/api/*.py Updated to use self._app instead of self.app following test base class changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +169 to +170
url = flower_app.get_url()
logger.info("Visit me at %s", url)
Copy link
Author

Choose a reason for hiding this comment

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

This is the fix. We get the URL from the Flower app. Before we got it from the Celery app before the server started.

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.

Flower Shows "Visit me at http://0.0.0.0:0" with --port=0

2 participants