LibreTime: Radio Broadcast & Automation Platform
Go to file
Scott McGrath 5b4c720e10
fix(playout): improve the way hashlib is called in libretime_playout/player (#3135)
### Description

Improves the way hashlib is called in libretime_playout/player so that
is isn't broken on systems with python < 3.9

The way it is currently called in
site-packages/libretime_playout/player/file.py, in the section where
scheduled files are copied to the cache dir for playout, specifies the
usedforsecurity=False flag as follows:
`hasher = hashlib.md5(usedforsecurity=False)`

hashlib.md5 did not support this flag until Python 3.9. Attempting to
specify the flag directly as an argument to hashlib.md5(), in an older
python environment (such as that in Ubuntu Focal 20.04), is unsafe, and
can cause hashlib.md5() to balk/throw an exception, which results in
file copy operations failing. This then precipitates into playout
problems, as scheduled media is missing from the cache folder.


This PR instead calls using hashlib.new(), and passes the argument to
that, as follows:
`hasher = hashlib.new('md5', usedforsecurity=False)`

This method of calling with the flag argument is safer, because the
constructor will take it or leave it gracefully, regardless of whether
the system has a version of hashlib that supports the `usedforsecurity`
flag. AFAICT, it improves (fixes) function on older systems without
negatively impacting others.

### Testing Notes

**What I did:**
Before applying this patch, we were experiencing occasional but fairly
regular periods of silence when the system was supposed to be playing a
song or track. This behavior was consistent with errors such as the
following being present in the playout log:
```
2025-01-15 14:01:28,331 | INFO     | libretime_playout.player.file:copy_file:47 - copying file 19834 to cache /var/lib/libretime/playout/scheduler/19834.mp3
2025-01-15 14:01:28,466 | ERROR    | libretime_playout.player.file:copy_file:77 - could not copy file 19834 to /var/lib/libretime/playout/scheduler/19834.mp3: 'usedforsecurity' is an invalid keyword argument for openssl_md5()
Traceback (most recent call last):
  File "/opt/libretime/lib/python3.8/site-packages/libretime_playout/player/file.py", line 70, in copy_file
    file_event.filesize = self.report_file_size_and_md5_to_api(
  File "/opt/libretime/lib/python3.8/site-packages/libretime_playout/player/file.py", line 89, in report_file_size_and_md5_to_api
    hasher = hashlib.md5(usedforsecurity=False)
TypeError: 'usedforsecurity' is an invalid keyword argument for openssl_md5()
```
_For more information about the characterization and results of this
problem, see issue #3134_

**Testing on running systems**
After the patch was applied, these errors were no longer seen. I first
tested this on a dev server, and then on a live server, with
approximately 100 distinct tracks of playout occurring over about 24
hours. There were no file copy failures, and no related playout
problems, which was a major and immediate improvement.

**Testing installer, fresh installs**
***Ubuntu 20.04***
I deployed a patch to the installer and installed it on a blank system
running Ubuntu 20.04 and tested it to make sure the fix was applied and
worked.

***Debian 11***
I deployed patch to the installer and installed it on a blank system
running Debian Bullseye (which runs python = 3.9) , and tested it there
to make sure it did not break anything or introduce a regression.


### **Links**

Closes: #3134
2025-01-17 23:11:02 +00:00
.github ci: only check last commit for API schema in PRs (#3133) 2025-01-10 16:56:39 +00:00
analyzer feat(analyzer): parse comment fields from mp3 files (#3082) 2024-11-22 18:28:06 +00:00
api feat(api): added filters on genre & md5 for files api (#3127) 2025-01-08 16:54:53 +00:00
api-client chore(main): release 4.2.0 (#3028) 2024-06-22 18:16:49 +02:00
dev chore: add mailpit to dev setup 2023-06-02 07:44:34 +01:00
docker feat!: use nginx to serve media files (#2860) 2023-12-30 18:59:15 +01:00
docs chore: update docker compose commands (#3132) 2025-01-09 16:09:28 +00:00
installer feat(installer): add the `--storage-path` flag (#2865) 2024-01-01 14:38:05 +01:00
legacy feat: add flac support to Web player (#3128) 2025-01-10 15:46:18 +00:00
playout fix(playout): improve the way hashlib is called in libretime_playout/player (#3135) 2025-01-17 23:11:02 +00:00
shared chore(main): release 4.2.0 (#3028) 2024-06-22 18:16:49 +02:00
tools fix: pin pip version to <24.1 to allow installing pytz (celery) (#3043) 2024-06-22 17:35:30 +02:00
worker chore(main): release 4.2.0 (#3028) 2024-06-22 18:16:49 +02:00
.codespellignore chore: release 3.2.0 (#2754) 2023-10-16 21:26:59 +02:00
.dockerignore feat: add container setup 2022-09-14 11:09:52 +02:00
.env.dev chore: move dev env files to dev subfolder 2023-04-12 08:11:21 +01:00
.gitattributes Create .gitattributes to ensure proper cloning with Windows Git 2017-04-09 14:41:52 -04:00
.gitignore chore: use a secure dev environment 2023-04-12 08:11:21 +01:00
.pre-commit-config.yaml chore: add pre-commit API check (#3120) 2025-01-09 07:53:49 +00:00
.vale.ini chore: reenable vale rule after fix (#2965) 2024-03-02 14:15:50 +01:00
CHANGELOG.md chore(main): release 4.2.0 (#3028) 2024-06-22 18:16:49 +02:00
CONTRIBUTING.md chore: fix CONTRIBUTING symlink again 2023-04-03 12:39:24 +02:00
Dockerfile fix: docker warnings "keywords casing do not match" (#3048) 2024-06-29 20:26:44 +01:00
LEGACY.md Add Table of Content to LEGACY file 2021-09-02 20:55:16 +02:00
LICENSE Small update to LICENSE 2021-09-02 16:06:26 +02:00
Makefile chore: update docker compose commands (#3132) 2025-01-09 16:09:28 +00:00
README.md chore: fix broken link check (#3039) 2024-06-22 11:44:35 +02:00
SECURITY.md docs: move release docs in the release section 2023-04-12 16:50:04 +01:00
Vagrantfile feat(installer)!: change default listen port to 8080 (#2852) 2023-12-29 17:49:07 +01:00
cloud-init.yml feat: rewrite cloud-init config (#2853) 2023-12-29 17:57:59 +01:00
codecov.yml test(worker): setup testing 2022-09-09 14:44:37 +02:00
docker-bake.json ci: use bake file for container build 2023-02-26 20:37:27 +02:00
docker-compose.override.yml fix: remove obsolete docker compose version (#2982) 2024-04-13 14:37:04 +02:00
docker-compose.yml perf: optimize the rabbitmq health check (#3037) 2024-06-22 18:10:55 +02:00
install fix: pin pip version to <24.1 to allow installing pytz (celery) (#3043) 2024-06-22 17:35:30 +02:00
pyproject.toml chore: add isort pre-commit hook 2023-02-03 12:38:58 +01:00

README.md

LibreTime

Financial Contributors on Open Collective

LibreTime makes it easy to run your own online or terrestrial radio station. It is a community managed fork of the AirTime project.

It is managed by a friendly inclusive community of stations from around the globe that use, document and improve LibreTime. Join us in fixing bugs and in defining how we manage the codebase going forward.

Check out the documentation for more information and start broadcasting!

Please note that LibreTime is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

You can find details about our development process in the contributing guide.

Support

To get support for any questions or problems you might have using the software we have a forum at discourse.libretime.org. We are moving towards using the forum to provide community support and reserving the github issue queue for confirmed bugs and well-formed feature requests.

You can also contact us through Matrix (#libretime:matrix.org) where you can talk with other users and developers.

Contributors

Code Contributors

This project exists thanks to all the people who contribute.

Financial Contributors

Become a financial contributor and help us sustain our community on OpenCollective.

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website.

License

LibreTime is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

Copyright (c) 2011-2017 Sourcefabric z.ú.

Copyright (c) 2017-2023 LibreTime Community

Please refer to the LEGACY file for more information.