Latency keeps increasing indefinitely when long-lived streams are present
I first noticed the issue several months ago, but I wasn't sure how to debug it. When I leave LMMS open for several days, the latency from MIDI key press to audio output gradually increases until it reaches low hundreds of ms, making it very noticeable.
I first thought it is a MIDI latency problem in LMMS, but later I found out other input methods are affected as well, and a week ago the latency became so extreme that I finally realized it is not a LMMS issue at all: I was in a video call and the image on the camera very obviously preceded the audio. It turned out that the latency of the main sink (and some related modules) was over 800 ms.
When I close LMMS and make sure no other application is generating sound, the latency usually resets and drops to zero (but not always: as I'm writing this, it is still stuck at 246 ms). My theory is that LMMS outputs audio even when technically playing silence, therefore keeping the sink busy. If for any reason the latency increases, it is locked-in and does not decrease until the sink becomes idle. I assume it should be also possible to reproduce the issue by simply running
paplay --raw /dev/zero in the background, but I haven't tested that yet.
I'm not sure why would the latency rise so high, but my guess is that it could be a response to out-of-memory situations (i.e. the system freezes for a while, audio buffer runs out and PA thinks it needs to increase buffer size to prevent future underflows?) But I have no clue how PA works internally and if that's something it can be doing.
This graph shows the latency increases over a week, sampled once per minute. Note that they are irregular (even though following a vaguely logarithmic shape), that's why I assume the latency depends on external events like OOM and isn't simply a function of time.
pa-info log: painfo.log
Steps to reproduce
Start LMMS (or possibly
paplay --raw /dev/zero), wait for a few hours or days and look for permanent latency increase on the main sink. Possibly bring the system under memory pressure to trigger the increases (still not 100 % sure on that).
What is the current bug behavior?
Latency keeps increasing indefinitely.
What is the expected correct behavior?
Latency either never increases over some hard threshold (300 ms may still be acceptable and even required when streaming over network, but 800 ms seems far from acceptable in most situations), or it is gradually reduced when possible (I assume that is not possible, since the buffer is full of data and there is no way to tell when is it safe to drop any of them, other than perhaps checking if all samples are zero).