-
Notifications
You must be signed in to change notification settings - Fork 328
Description
In our environment, we're getting spurious exceptions like this:
Oct 03 13:27:05 donate-01 donate[949]: /usr/bin/sox FAIL formats: can't open input file `/tmp/1a0e906c0bb38acf4526812068c1e497d90c1b4d_arbitrary.wav': No such file or directory
Oct 03 13:27:05 donate-01 donate[949]: [ERROR: django.request.log_response] Internal Server Error: /captcha/audio/1a0e906c0bb38acf4526812068c1e497d90c1b4d.wav
Oct 03 13:27:05 donate-01 donate[949]: Traceback (most recent call last):
Oct 03 13:27:05 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
Oct 03 13:27:05 donate-01 donate[949]: response = get_response(request)
Oct 03 13:27:05 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^
Oct 03 13:27:05 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
Oct 03 13:27:05 donate-01 donate[949]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
Oct 03 13:27:05 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 03 13:27:05 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/captcha/views.py", line 197, in captcha_audio
Oct 03 13:27:05 donate-01 donate[949]: os.remove(arbnoisepath)
Oct 03 13:27:05 donate-01 donate[949]: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/1a0e906c0bb38acf4526812068c1e497d90c1b4d_arbitrary.wav'
Oct 03 13:27:05 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/1a0e906c0bb38acf4526812068c1e497d90c1b4d.wav HTTP/1.1" 500 6628 45
Oct 03 13:27:05 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/1a0e906c0bb38acf4526812068c1e497d90c1b4d.wav HTTP/1.1" 200 33088 33
Oct 03 13:27:05 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/image/a0f3b95e27cdadccd06aacb165004bf80ea4b97d/ HTTP/1.1" 200 6001 7
Oct 03 13:27:05 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/a0f3b95e27cdadccd06aacb165004bf80ea4b97d.wav HTTP/1.1" 206 32044 31
Oct 03 13:27:07 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/a0f3b95e27cdadccd06aacb165004bf80ea4b97d.wav HTTP/1.1" 200 32044 30
Oct 03 13:27:07 donate-01 donate[949]: /usr/bin/sox FAIL formats: can't open input file `/tmp/a0f3b95e27cdadccd06aacb165004bf80ea4b97d_arbitrary.wav': No such file or directory
Oct 03 13:27:07 donate-01 donate[949]: [ERROR: django.request.log_response] Internal Server Error: /captcha/audio/a0f3b95e27cdadccd06aacb165004bf80ea4b97d.wav
Oct 03 13:27:07 donate-01 donate[949]: Traceback (most recent call last):
Oct 03 13:27:07 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
Oct 03 13:27:07 donate-01 donate[949]: response = get_response(request)
Oct 03 13:27:07 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^
Oct 03 13:27:07 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
Oct 03 13:27:07 donate-01 donate[949]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
Oct 03 13:27:07 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 03 13:27:07 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/captcha/views.py", line 197, in captcha_audio
Oct 03 13:27:07 donate-01 donate[949]: os.remove(arbnoisepath)
Oct 03 13:27:07 donate-01 donate[949]: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/a0f3b95e27cdadccd06aacb165004bf80ea4b97d_arbitrary.wav'
Oct 03 13:27:07 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/a0f3b95e27cdadccd06aacb165004bf80ea4b97d.wav HTTP/1.1" 500 6628 24
[...]
Oct 03 14:31:41 donate-01 donate[949]: /usr/bin/sox FAIL formats: can't open input file `/tmp/ed9879ca11de0a7ad7f3d910793f888af26b4d3d_arbitrary.wav': WAVE: RIFF header not found
Oct 03 14:31:41 donate-01 donate[949]: [ERROR: django.request.log_response] Internal Server Error: /captcha/audio/ed9879ca11de0a7ad7f3d910793f888af26b4d3d.wav
Oct 03 14:31:41 donate-01 donate[949]: Traceback (most recent call last):
Oct 03 14:31:41 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
Oct 03 14:31:41 donate-01 donate[949]: response = get_response(request)
Oct 03 14:31:41 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^
Oct 03 14:31:41 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
Oct 03 14:31:41 donate-01 donate[949]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
Oct 03 14:31:41 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 03 14:31:41 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/captcha/views.py", line 199, in captcha_audio
Oct 03 14:31:41 donate-01 donate[949]: os.rename(mergedpath, path)
Oct 03 14:31:41 donate-01 donate[949]: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ed9879ca11de0a7ad7f3d910793f888af26b4d3d_merged.wav' -> '/tmp/ed9879ca11de0a7ad7f3d910793f888af26b4d3d.wav'
Oct 03 14:31:41 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/ed9879ca11de0a7ad7f3d910793f888af26b4d3d.wav HTTP/1.1" 500 6628 33
Oct 03 14:31:41 donate-01 donate[949]: /usr/bin/sox FAIL formats: can't open input file `/tmp/ed9879ca11de0a7ad7f3d910793f888af26b4d3d.wav': No such file or directory
Oct 03 14:31:41 donate-01 donate[949]: [ERROR: django.request.log_response] Internal Server Error: /captcha/audio/ed9879ca11de0a7ad7f3d910793f888af26b4d3d.wav
Oct 03 14:31:41 donate-01 donate[949]: Traceback (most recent call last):
Oct 03 14:31:41 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
Oct 03 14:31:41 donate-01 donate[949]: response = get_response(request)
Oct 03 14:31:41 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^
Oct 03 14:31:41 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
Oct 03 14:31:41 donate-01 donate[949]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
Oct 03 14:31:41 donate-01 donate[949]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 03 14:31:41 donate-01 donate[949]: File "/home/tordonate/venv/lib/python3.11/site-packages/captcha/views.py", line 197, in captcha_audio
Oct 03 14:31:41 donate-01 donate[949]: os.remove(arbnoisepath)
Oct 03 14:31:41 donate-01 donate[949]: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ed9879ca11de0a7ad7f3d910793f888af26b4d3d_arbitrary.wav'
Oct 03 14:31:41 donate-01 donate[949]: 0.0.0.0 - "GET /captcha/audio/ed9879ca11de0a7ad7f3d910793f888af26b4d3d.wav HTTP/1.1" 500 6628 30
it's unclear why this is happening, we suspect it might be related with multithreading issues in the codebase and lack of locking. we also have issues with old captcha files not being cleaned up for example.
but exactly why this is happening is somewhat besides the point: such failures should at least be handled better than a 500 error with a backtrace. we should add exception handling in (e.g.) this code:
django-simple-captcha/captcha/views.py
Lines 165 to 199 in 153cfd9
| if settings.CAPTCHA_SOX_PATH: | |
| arbnoisepath = str( | |
| os.path.join(tempfile.gettempdir(), "%s_arbitrary.wav") % key | |
| ) | |
| mergedpath = str(os.path.join(tempfile.gettempdir(), "%s_merged.wav") % key) | |
| subprocess.call( | |
| [ | |
| settings.CAPTCHA_SOX_PATH, | |
| "-r", | |
| "8000", | |
| "-n", | |
| arbnoisepath, | |
| "synth", | |
| "2", | |
| "brownnoise", | |
| "gain", | |
| "-15", | |
| ] | |
| ) | |
| subprocess.call( | |
| [ | |
| settings.CAPTCHA_SOX_PATH, | |
| "-m", | |
| arbnoisepath, | |
| path, | |
| "-t", | |
| "wavpcm", | |
| "-b", | |
| "16", | |
| mergedpath, | |
| ] | |
| ) | |
| os.remove(arbnoisepath) | |
| os.remove(path) | |
| os.rename(mergedpath, path) |
so that we can somewhat recover more gracefully when that happens. if at least this was a custom exception from this module (instead of a fairly generic OSError/FileNotFoundError, we could handle it (or ignore it, at least for now) differently than other exceptions...
i'd be happy to propose a PR to at least do the latter if there's an opening here.
Note that this issue is tracked at https://gitlab.torproject.org/tpo/web/donate-neo/-/issues/142 where you can also see the entire source code for this project.