Bug 339913 - KMix tries to reconnect to pulseaudio daemon every 50ms
Summary: KMix tries to reconnect to pulseaudio daemon every 50ms
Status: RESOLVED WORKSFORME
Alias: None
Product: kmix
Classification: Applications
Component: Backend: Pulseaudio (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Colin Guthrie
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-12 21:10 UTC by Stefan Brüns
Modified: 2022-11-25 05:22 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Patch as posted in the Debian bugtracker (1.12 KB, patch)
2016-10-25 11:45 UTC, Maximiliano Curia
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Brüns 2014-10-12 21:10:54 UTC
If the connection fails, a new connection is triggered from
context_state_callback(pa_context *c, void *)
using
QTimer::singleShot(50, s_mixers[KMIXPA_PLAYBACK], SLOT(reinit()));

Depending on how long it takes from starting the connection attempt to PA_CONTEXT_FAILED, up to 20 connection attempts are made per second.

A exponential backoff with a limit of 10s would be better here.

Reproducible: Always
Comment 1 Stefan Brüns 2014-10-13 23:49:17 UTC
This happens if PULSE_SERVER is set to a remote location and the remote is currently not available.

pa_context_connect returns 0 in this case, and the state callback is called with pa_state == FAILED.
Comment 2 Maximiliano Curia 2016-10-25 11:45:12 UTC
We have received a patch for this issue in the Debian bugtracker in the bug:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=789887

which still seems to apply.

Index: kmix-4.14.0/backends/mixer_pulse.cpp
===================================================================
--- kmix-4.14.0.orig/backends/mixer_pulse.cpp
+++ kmix-4.14.0/backends/mixer_pulse.cpp
@@ -37,6 +37,8 @@
 #  include <canberra.h>
 #endif
 
+#include <time.h>
+
 // PA_VOLUME_UI_MAX landed in pulseaudio-0.9.23, so this can be removed when/if
 // minimum requirement is ever bumped up (from 0.9.12 currently)
 #ifndef PA_VOLUME_UI_MAX
@@ -716,7 +718,14 @@ static void context_state_callback(pa_co
             if (s_mixers.contains(KMIXPA_PLAYBACK)) {
                 kWarning(67100) << "Connection to PulseAudio daemon closed. Attempting reconnection.";
                 s_pulseActive = UNKNOWN;
-                QTimer::singleShot(50, s_mixers[KMIXPA_PLAYBACK], SLOT(reinit()));
+		static time_t last_timestamp = 0;
+		time_t current_time = time(NULL);
+		if ((current_time - last_timestamp) > 3) {
+		  QTimer::singleShot(50, s_mixers[KMIXPA_PLAYBACK], SLOT(reinit()));
+		} else {
+		  QTimer::singleShot(60000, s_mixers[KMIXPA_PLAYBACK], SLOT(reinit()));
+		}
+		last_timestamp = current_time;
             }
         }
     }
Comment 3 Maximiliano Curia 2016-10-25 11:45:59 UTC
Created attachment 101774 [details]
Patch as posted in the Debian bugtracker
Comment 4 Justin Zobel 2022-10-26 03:07:12 UTC
Thank you for reporting this bug in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you!
Comment 5 Bug Janitor Service 2022-11-10 05:11:47 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Bug Janitor Service 2022-11-25 05:22:03 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!