FS#69620 - [timidity++] ALSA output runs into "cannot get status", unusable afterwards

Attached to Project: Community Packages
Opened by Na Sowas (nasowas) - Thursday, 11 February 2021, 21:10 GMT
Last edited by David Thurstenson (thurstylark) - Sunday, 01 May 2022, 14:39 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To David Runge (dvzrv)
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

When using a system with plain ALSA (i.e. no JACK, no PulseAudio), timidity -Os eventually crashes or runs into an infinite loop with "cannot get status", given enough load.

Steps to reproduce (alternative 1):

* Get a nice soundfont, e.g. "soundfont-sgm" (AUR).
* Run timidity with a sufficiently complex MIDI file, e.g.

$ timidity -a -A 70 -p256 -EwpvseToz -EFchorus=n -EFreverb=f,63 -x"soundfont /usr/share/soundfonts/SGM-V2.01.sf2" -B 1,1 -Os -s44100 --verbose=2 some_complex_midi_file.mid

* Wait for it to crash with "cannot get status". Loading the CPU with some other processes might help. For me, it crashes in the first few seconds.

Steps to reproduce (alternative 2):

* Alternatively, run it as an ALSA sequencer client, e.g.

$ timidity -a -A 70 -p256 -EwpvseToz -EFchorus=n -EFreverb=f,63 -x"soundfont /usr/share/soundfonts/SGM-V2.01.sf2" -B 1,1 -Os -s44100 -iA --realtime-priority=6 --verbose=2

* Now, try to interact with timidity, e.g. by using rosegarden, and give it some load by using your MIDI keyboard, playing back a file, etc. For me, even a simple program change can trigger this issue.
* BEWARE! The --verbose=2 will spam your logs with "cannot get status" as soon as this issue is triggered.
* Even if you do not set verbosity, whenever it runs into that issue, you will get high CPU load and an unusable timidity that needs to be restarted, only to fail again later.
* Note that I am used to running timidity -iA as root so --realtime-priority=6 would work, but it does not affect the outcome.
* Note that setting -B to higher values only delays the practically inevitable "crash".

This is what I found out about this issue, and how:

$ git clone https://git.code.sf.net/p/timidity/git timidity-git
$ cd timidity-git
$ grep -Hrn -C3 -F 'cannot get status' . # points to timidity/alsa_a.c

Then, in timidity/alsa_a.c near line 548, we see a related function call to snd_pcm_status which is probably this one:

https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#ga32891eaac37741728a9b23027012c892

There, it reads: "The function is thread-safe when built with the proper option."

So maybe some compiler flags or the build process is broken?

# pacman -Qi timidity # output shortened for brevity:
Name : timidity++
Version : 2.15.0-5
Architecture : x86_64
Build Date : Thu 03 Dec 2020 07:21:41 PM CET

I remember that it worked flawlessly back in summer 2020, then it started to fall apart at some point in autumn. It got worse near the end of 2020 (although this might be due to the config dir change I noticed only recently).

$ asp checkout timidity++
$ cd timidity++
$ git log

The git log pretty much reflects the experienced changes in the past as I remember them, so it is probably due to commit d38a575bf526ea9a7abc744f45717a2537b8b2f0, or a more recent change.

Note: I know that using JACK might be more appropriate for some use cases, but I am not used to it (as I did not find the time), and there might be other parts of timidity that are still affected by these compilation issues as well (assuming that this is where the issue come from). In the past and with my setup, timidity as an ALSA sequencer client used to work with delays short enough to make live input from a MIDI keyboard possible, even without a realtime kernel, and even with -B1,1. (I tried some rt tweaks but to no avail.) At worst, I got buffer underruns, but it never "crashed".
This task depends upon

Closed by  David Thurstenson (thurstylark)
Sunday, 01 May 2022, 14:39 GMT
Reason for closing:  No response
Comment by David Runge (dvzrv) - Saturday, 10 April 2021, 07:50 GMT
@nasowas: Thanks for the report.

From what I can see, the only difference in the commit you mention [1] is, that opposite to when a fix for missing full RELRO was introduced [2], the patch also modifies Makefile.in (the initial sed only fixed Makefile.am) to accept our LDFLAGS.

Can you build the package without the patch for full RELRO applied (just comment the line [3]) and see whether that fixes your issue?

Other than that: It is always a good idea to report these types of issues to upstream.

[1] https://github.com/archlinux/svntogit-community/commit/d38a575bf526ea9a7abc744f45717a2537b8b2f0#diff-3e341d2d9c67be01819b25b25d5e53ea3cdf3a38d28846cda85a195eb9b7203a
[2] https://github.com/archlinux/svntogit-community/commit/7493988b2aea55b15afc69ebe50e30a0f0bb42ce#diff-3e341d2d9c67be01819b25b25d5e53ea3cdf3a38d28846cda85a195eb9b7203a
[3] https://github.com/archlinux/svntogit-community/blob/50a67ae3b6c54e7553101ccc2faa3383a9ece2e5/trunk/PKGBUILD#L44
Comment by Na Sowas (nasowas) - Friday, 16 April 2021, 17:23 GMT
@dvzrv: Thank you for taking care of this issue.

This is strange. I ran makepkg on a clean directory each time for each of the 12 commits, hoping that this issue might disappear by simply going back in time. However, every single time, I got this unwanted behavior. Then, as per your suggestion, I removed the patch call for the ldflags patch file, to no avail. Then, I also removed the JACK-related patch, still no change. Then, I modified PKGBUILD to try and make it compile timidity++ 2.14.0 (based on TiMidity++-2.14.0.tar.xz dated 2012-06-29), but during compilation, I ran into an error, probably because it is way too old.

Can you reproduce this issue? I just installed both timidity++-2.15.0-5 and rosegarden-20.12-1 straight from the Arch repos on a very different machine (where I never installed anything MIDI-related before), along with the soundfont mentioned above from my cache. The results:

* I did not yet manage to reproduce this unwanted behavior when playing back a MIDI file in a terminal emulator, maybe this is because that second machine is much more powerful.

* However, I immediately ran into that issue again when I tried to use timidity as an ALSA sequencer client together with rosegarden on that second machine.
Comment by David Thurstenson (thurstylark) - Saturday, 12 March 2022, 20:57 GMT
Before closing for inactivity: Any progress on this issue?

Loading...