core
core copied to clipboard
Fix blocking stat call in local media_source
Proposed change
fixes
2024-10-04 11:43:31.902 WARNING (MainThread) [homeassistant.block_async_io] Checking if /Users/bdraco/media/file_example_MP3_2MG.mp3 is allowed
2024-10-04 11:43:31.927 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to stat with args (PosixPath(/Users/bdraco/media/file_example_MP3_2MG.mp3),) inside the event loop by integration media_source at homeassistant/components/media_source/local_source.py, line 228: if not media_path.is_file(): (offender: /opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pathlib.py, line 840: return os.stat(self, follow_symlinks=follow_symlinks)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+media_source%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#stat
Traceback (most recent call last):
File "/Users/bdraco/home-assistant/venv/bin/hass", line 8, in <module>
sys.exit(main())
File "/Users/bdraco/home-assistant/homeassistant/__main__.py", line 209, in main
exit_code = runner.run(runtime_conf)
File "/Users/bdraco/home-assistant/homeassistant/runner.py", line 189, in run
return loop.run_until_complete(setup_and_run_hass(runtime_config))
File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
self.run_forever()
File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
self._run_once()
File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1987, in _run_once
handle._run()
File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/Users/bdraco/home-assistant/venv/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 556, in start
task = asyncio.Task(coro, loop=loop, eager_start=True)
File "/Users/bdraco/home-assistant/venv/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
resp = await request_handler(request)
File "/Users/bdraco/home-assistant/venv/lib/python3.12/site-packages/aiohttp/web_app.py", line 559, in _handle
return await handler(request)
File "/Users/bdraco/home-assistant/venv/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/components/http/security_filter.py", line 97, in security_filter_middleware
return await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
return await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
return await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
return await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
return await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
response = await handler(request)
File "/Users/bdraco/home-assistant/homeassistant/helpers/http.py", line 73, in handle
result = await handler(request, **request.match_info)
File "/Users/bdraco/home-assistant/homeassistant/components/media_source/local_source.py", line 228, in get
if not media_path.is_file():
Type of change
- [ ] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
Checklist
- [ ] The code change is tested and works locally.
- [ ] Local tests pass. Your PR cannot be merged unless tests pass
- [ ] There is no commented out code in this PR.
- [ ] I have followed the development checklist
- [ ] I have followed the perfect PR recommendations
- [ ] The code has been formatted using Ruff (
ruff format homeassistant tests) - [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for www.home-assistant.io
If the code communicates with devices, web services, or third-party tools:
- [ ] The manifest file has all fields filled out correctly.
Updated and included derived files by running:python3 -m script.hassfest. - [ ] New or updated dependencies have been added to
requirements_all.txt.
Updated by runningpython3 -m script.gen_requirements_all. - [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
To help with the load of incoming pull requests:
- [ ] I have reviewed two other open pull requests in this repository.
Hey there @hunterjm, mind taking a look at this pull request as it has been labeled with an integration (media_source) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of media_source can trigger bot actions by commenting:
@home-assistant closeCloses the pull request.@home-assistant rename Awesome new titleRenames the pull request.@home-assistant reopenReopen the pull request.@home-assistant unassign media_sourceRemoves the current integration label and assignees on the pull request, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.
thanks