hydrogen-music / hydrogen

The advanced drum machine for Linux, macOS, and Windows
http://www.hydrogen-music.org
GNU General Public License v2.0
1.04k stars 173 forks source link

Fix JACK support #1926

Closed theGreatWhiteShark closed 9 months ago

theGreatWhiteShark commented 9 months ago

Probably due to some upstream JACK bugs (not sure) Hydrogen does occassionally segfault when stopping the JackAudioDriver. Turns out JACK has a number of issues with thread joining. During teardown of the driver we must ensure it does not do any communication, like locking the AudioEngine or enqueuing a message in our Logger. Otherwise the thread calling jack_client_close might segfault.

Now, the callback of the AudioEngine checks its state twice. Once without locking (in order to return when it is not ready yet/anymore) and another time while locked to properly check the state. It is a little dirty. But I do not see what else we can do from within the Hydrogen code base

Fixes #1929


Previous text:

Lately we have quite a number of reports of Hydrogen crashing during shutdown or song export all related to our JackAudioDriver (#1902, #1907, #1867).

I have to admit I have seen those for quite a while now on my device. But since they are occurring very rarely (like one out of 20) and neither my Hydrogen nor JACK are in a "production" setup, I didn't bothered after giving it a first, inconclusive shot. But the JACK version I use (1.9.21) seems to tickle down the package repos and more and more users get the same issues as well.

I wrote a Go-based integration test starting up Hydrogen hundreds of times and killing it via OSC right away. This way I'm now able to reproduce the issue.

So far it looks like this is an upstream problem and code of JACK crashes when attempting to tear down the JackAudioDriver. We might need a way to protect against crashing driver code. But I'm far from understand what is going on and still need to check and read into a couple of things first.

theGreatWhiteShark commented 9 months ago

Another problem: Occassionally upstream JACK code used in our JackAudioDriver gets trapped in a deadlock when stopping the driver (see https://github.com/jackaudio/jack2/issues/395).

This does not occur as often as the crashes on my machine. But is still annoying.