Skip to content

Celery not starting correctly when LOG_FILE is empty #10555

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

Closed
5 tasks done
fdb02983rhy opened this issue Nov 11, 2024 · 6 comments · Fixed by #10563
Closed
5 tasks done

Celery not starting correctly when LOG_FILE is empty #10555

fdb02983rhy opened this issue Nov 11, 2024 · 6 comments · Fixed by #10563
Labels
🐞 bug Something isn't working

Comments

@fdb02983rhy
Copy link
Contributor

fdb02983rhy commented Nov 11, 2024

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Keep the LOG_FILE environment variable empty then run docker compose

✔️ Expected Behavior

Celery can starts successfully even the LOG_FILE is not set or empty.

❌ Actual Behavior

Celery cannot starts successfully even the LOG_FILE is not set or empty.

worker-1      | Traceback (most recent call last):
worker-1      |   File "/app/api/.venv/bin/celery", line 8, in <module>
worker-1      |     sys.exit(main())
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/__main__.py", line 15, in main
worker-1      |     sys.exit(_main())
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/bin/celery.py", line 236, in main
worker-1      |     return celery(auto_envvar_prefix="CELERY")
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
worker-1      |     return self.main(*args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
worker-1      |     rv = self.invoke(ctx)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
worker-1      |     return _process_result(sub_ctx.command.invoke(sub_ctx))
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
worker-1      |     return ctx.invoke(self.callback, **ctx.params)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
worker-1      |     return __callback(*args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
worker-1      |     return f(get_current_context(), *args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/bin/base.py", line 135, in caller
worker-1      |     return f(ctx, *args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/bin/worker.py", line 348, in worker
worker-1      |     worker = app.Worker(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/worker/worker.py", line 98, in __init__
worker-1      |     self.setup_instance(**self.prepare_args(**kwargs))
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/worker/worker.py", line 131, in setup_instance
worker-1      |     self.on_init_blueprint()
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/apps/worker.py", line 116, in on_init_blueprint
worker-1      |     self._custom_logging = self.setup_logging()
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/apps/worker.py", line 180, in setup_logging
worker-1      |     return self.app.log.setup(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 63, in setup
worker-1      |     handled = self.setup_logging_subsystem(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 117, in setup_logging_subsystem
worker-1      |     self._configure_logger(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 150, in _configure_logger
worker-1      |     self.setup_handlers(logger, logfile, format,
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 216, in setup_handlers
worker-1      |     handler = self._detect_handler(logfile)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 226, in _detect_handler
worker-1      |     return WatchedFileHandler(logfile, encoding='utf-8')
worker-1      |   File "/usr/local/lib/python3.10/logging/handlers.py", line 479, in __init__
worker-1      |     logging.FileHandler.__init__(self, filename, mode=mode,
worker-1      |   File "/usr/local/lib/python3.10/logging/__init__.py", line 1169, in __init__
worker-1      |     StreamHandler.__init__(self, self._open())
worker-1      |   File "/usr/local/lib/python3.10/logging/__init__.py", line 1201, in _open
worker-1      |     return open_func(self.baseFilename, self.mode,
worker-1      | IsADirectoryError: [Errno 21] Is a directory: '/app/api'
Copy link

dosubot bot commented Nov 11, 2024

Celery fails to start when the LOG_FILE setting is empty because it defaults to a directory path instead of a file path, leading to an "IsADirectoryError". To resolve this, ensure that the LOG_FILE environment variable is set to a valid file path where logs can be written. This can be done by specifying a file path in your docker-compose.yaml configuration under the LOG_FILE environment variable [1].

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the 🐞 bug Something isn't working label Nov 11, 2024
@fujita-h
Copy link
Contributor

I'm confirming the same issue.

@xiandan-erizo
Copy link
Contributor

可以在环境变量中修改LOG_FILE,临时解决

@yuzp-work
Copy link

yuzp-work commented Nov 12, 2024

+1, this issue looks still here in 0.11.1

@nicklhy
Copy link

nicklhy commented Nov 12, 2024

+1

@rxue92
Copy link

rxue92 commented Nov 12, 2024

FYI: If you don't need log file persistence and just want the worker container to start correctly, you can set the LOG_FILE variable in the .env file as shown below and run docker compose up -d.

# ------------------------------
# Server Configuration
# ------------------------------

# The log level for the application.
# Supported values are `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
LOG_LEVEL=INFO
# Log file path
LOG_FILE=/app/logs/server.log
# Log file max size, the unit is MB
LOG_FILE_MAX_SIZE=20
# Log file max backup count
LOG_FILE_BACKUP_COUNT=5
# Log dateformat
LOG_DATEFORMAT=%Y-%m-%d %H:%M:%S

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants